Create a D3 axis without tick labels

前端 未结 3 1220
旧时难觅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:47

    I'm just going to leave this here since people are likely to end up on this question. Here are the different ways you can easily manipulate a D3 axis.

    • Without any ticks or tick labels:

      d3.svg.axis().tickValues([]);
      

      No line or text elements are created this way.

    • Without ticks and with tick labels:

      d3.svg.axis().tickSize(0);
      

      The line elements are still created this way.

      You can increase the distance between the tick labels and the axis with .tickPadding(10), for example.

    • With ticks and without tick labels:

      d3.svg.axis().tickFormat("");
      

      The text elements are still created this way.

提交回复
热议问题