D3 v4 - Get the value of the each tick present on an axis?

后端 未结 2 1730
被撕碎了的回忆
被撕碎了的回忆 2021-01-18 00:37

Using D3.js version 4, is there a way to get an array of the values for each tick on an axis?

Edit:

From D3 documentation

# axis.tickValue

2条回答
  •  离开以前
    2021-01-18 01:27

    If you have a reference to the axis, you can use:

    axis.scale().ticks()
    

    If you want them all formatted out, I'd get them from the DOM:

    d3.selectAll(".tick>text")
      .nodes()
      .map(function(t){
        return t.innerHTML;
      })
    

    Running code:

    
    
    
    
    

提交回复
热议问题