How can I get the D3.js axis ticks and positions as an array?

前端 未结 2 1686
醉梦人生
醉梦人生 2021-01-07 17:20

I usually place my axis ticks on the svg using this:

d3.svg.axis().scale(xScale(width)).ticks(4)

Is it possible to get these tick values a

2条回答
  •  暖寄归人
    2021-01-07 17:47

    In d3 v4 I ended up just parsing the rendered x values from the tick nodes

    function parseX(transformText) {
        let m = transformText.match(/translate\(([0-9\.]*)/);
        let x = m[1];
        if (x) {
            return parseFloat(x);
        }
    }
    

提交回复
热议问题