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).
You can programatically set the number of ticks to data.length - 1 (this solves the issue you were having for small numbers of ticks as well)
data.length - 1
var yAxis = d3.svg.axis() .scale(y) .orient("right") .tickFormat(d3.format("d")) .ticks(data.length - 1)