Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8899181
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 15, 20262026-06-15T00:47:51+00:00 2026-06-15T00:47:51+00:00

I am working with a bar chart that was based off of this ,

  • 0

I am working with a bar chart that was based off of this, and I want to modify the x-axis labels (either rotate them or only show every other or every third…something that will allow me to fit labels without their overlapping). I’ve spent quite a bit of time looking into this, but it seems easier said than done (although I am pretty new to d3). I believe the code segments that are in question are among these:

var x = d3.scale.ordinal()
  .rangeRoundBands([0, width], .1);

…

var xAxis = d3.svg.axis()
  .scale(x)
  .orient("bottom");

…

x.domain(data.map(function(d) { return d.State; }));

…above is where the mapping happens (I assume based on the ‘map’ function)

svg.append("g")
  .attr("class", "x axis")
  .attr("transform", "translate(0," + height + ")")
  .call(xAxis);

…

var state = svg.selectAll(".state")
  .data(data)
.enter().append("g")
  .attr("class", "g")
  .attr("transform", function(d) { return "translate(" + x(d.State) + ",0)"; });

…

  state.selectAll("rect")
  .data(function(d) { return d.ages; })
.enter().append("rect")
  .attr("width", x.rangeBand())
  .attr("y", function(d) { return y(d.y1); })
  .attr("height", function(d) { return y(d.y0) - y(d.y1); })
  .style("fill", function(d) { return color(d.name); });

The problem is that I don’t necessarily want an x-axis label for every bar in the chart (it gets too cluttered). I have already tried several different ways of using

axis.ticks
axis.tickValues
axis.tickSubdivide
axis.tickSize

but I think they fail because d.State is married to its respective column (my graph uses dates instead of the name of a state)…any insight?

Sorry for the messy question. I welcome edits by those who understand what I’m asking to make my question more clear (I’m not sure of the best way to ask it).

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-15T00:47:52+00:00Added an answer on June 15, 2026 at 12:47 am

    The line

    x.domain(data.map(function(d) { return d.State; }));
    

    Is setting the domain for the scale that the axis uses. Because the scale is ordinal the axis defaults to using all the values for ticks. You should be able to set the actual tick values using the axis.tickValues function you mention above. You will just have to set it after the call that sets the scale domain because I suspect setting the domain resets the tickValues. Simply add something like:

    xAxis.tickValues(data.map( function(d,i) 
      { 
        if(i % 2 ===0 ) return d.State; 
      })
        .filter(function (d) 
          { return !!d; } ));
    

    Here I am mapping the data data to a single array of selected State values interspersed with “undefined” and then filtering out all the undefineds. The remaining State values become the ticks.

    If you are using underscore you can probably make the line a lot prettier.

    You can see the working solution here.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am working on a simple app tab-bar based application that has two views.
I'm working on a Python script that transforms this: foo bar Into this: [[Component
I want to create a bar chart application in windows based .net application, i
i am working on an application that needs to scan bar codes as a
On this form, I create a grid, almost looks like a bar chart with
I have been working on a project that requires a bar graph to be
I am currently working on a task which want to display bar charts/tables on
Hy, I have a chart,wich is created in runtime,this could be Line, Bar or
I'm working on some bar charts and need to update the chart values. The
I should preface this by stating that I'm working with VB6 & RegExp I'm

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.