Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Create a D3 axis without tick labels

Tags:

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 several Axis objects rotated around the centre, and only the first one has tick labels.

In this case, he's achieved the result using CSS to hide all but the first axis's labels:

.axis + .axis g text {   display: none; } 

However this still results in the creation of SVG text elements in the DOM. Is there a way to avoid their generation altogether?

like image 697
Drew Noakes Avatar asked Nov 05 '13 11:11

Drew Noakes


People also ask

How do you turn off axis labels in python?

Matplotlib removes both labels and ticks by using xaxis. set_visible() set_visible() method removes axis ticks, axis tick labels, and axis labels also. It makes the axis invisible completely.

What is a tick mark on an axis?

A tick is a short line on an axis. For category axes, ticks separate each category. For value axes, ticks mark the major divisions and show the exact point on an axis that the axis label defines. Ticks are always the same color and line style as the axis.

What are ticks d3?

d3. ticks generates an array of nicely-rounded numbers inside an interval [start, stop]. The third argument indicates the approximate count of values needed. For example, to cover the extent [0, 10] with about 100 values, d3.ticks will return these ticks: start = 0.

How do you add a tick mark in Axis?

Add tick marks on an axisClick Add Chart Element > Axes > More Axis Options. On the Format Axis pane, expand Tick Marks, and then click options for major and minor tick mark types. After you add tick marks, you can change the intervals between the tick marks by changing the value in the Interval between marks box.


1 Answers

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.

like image 122
Ashitaka Avatar answered Jan 01 '23 21:01

Ashitaka