Create a D3 axis without tick labels

前端 未结 3 1249
旧时难觅i
旧时难觅i 2021-01-01 13:15

How can I create a D3 axis that does not have any labels at its tick markers?

Here\'s an example that shows what I\'m after, from Mike Bostock no less. There are sev

3条回答
  •  清酒与你
    2021-01-01 13:50

    You can't avoid the generation of the text elements without modifying the source. You can however remove those elements after they have been generated:

    var axisElements = svg.append("g").call(axis);
    axisElements.selectAll("text").remove();
    

    Overall, this is probably the most flexible way to approach this as you can also remove labels selectively. You can get the data used to generated them from the scale you're using (by calling scale.ticks()), which would allow you to easily do things like remove all the odd labels.

提交回复
热议问题