I have a d3 bar chart whose values range from 0-3. I would like the y-axis to only show integer values, which I can do by
var yAxis = d3.svg.axis().scale(y).
Used this TIP to make this work on dynamic charts (1 or more charts on page)
That did the trick. I changed to be Math.min(maxHeight+1,yAxis.ticks()) so if the graph height is less than the number of ticks, it reduces the number of ticks. – Jeff Storey Nov 28 '12 at 2:47
// It is either 10 or Maximum Chart height + 1
var graphValues = selection.data()[0].map(function(obj) {
return obj['count'];
}).compact();
Array.prototype.maxValArray = function() {
return Math.max.apply(null, this);
};
var maxValue = graphValues.maxValArray();
yAxis.ticks(Math.min(maxValue + 1, 10))