d3 tick marks on integers only

后端 未结 5 1498
旧巷少年郎
旧巷少年郎 2020-12-03 10:04

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).         


        
5条回答
  •  死守一世寂寞
    2020-12-03 10:31

    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)

    var yAxis = d3.svg.axis()
        .scale(y)
        .orient("right")
        .tickFormat(d3.format("d"))
        .ticks(data.length - 1)
    

提交回复
热议问题