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

后端 未结 2 1764
被撕碎了的回忆
被撕碎了的回忆 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:28

    I found the answer of Mark above was not correct for my case, I changed a bit from his inspiration and it worked

    // I am using d3-scale
    const yScale = scaleLinear().domain(realYDomain).range([30, 170]);
    // I am using d3-axis
    const yAxis = axisLeft(yScale); // Not declare axisLeft(scale).ticks(number) here, but below line instead
    const tickValues = yAxis.scale().ticks(5);
    console.log(tickValues);
    

提交回复
热议问题