I have 24 categories in my quantitative axis, and I’d like to display around 6 categories. I tried adding .ticks(6) to my axis, like this
var xAxis = d3.svg.axis()
.scale(x)
.orient("bottom")
.ticks(6);
but my graph still displays all 24 categories. The scale I’m using is
var x = d3.scale.ordinal()
.rangeRoundBands([0, width], .1, 1);
Any idea why this would happen?
The
.ticks()function doesn’t do anything for ordinal axes. Depending on what exactly you want to do, you might not need an axis anyway — simply place the labels you want with the points/bars/whatever you add for the categories.