Skip to content

Axes

Axes are a visual representation of position and extent scales. They are used to display how numerical quantities are transformed into physical positions and sizes inside the chart.

Often, the scales they represent are continuous linear transformations, but not always. Ordinal scales, where different categorical values are mapped to different positions, as well as logarithmic, quadratic, and exponential scales can also be displayed using axes. Usually, axes are positioned parallel to the visual dimension into which they transform data, hence the prominence of "x" and "y" axes. This is almost always the most readable and recognizable orientation.

Axis labels

Axis labels can be formatted very flexibly. A combination of ticks/tickValues and tickFormat is needed. The former to define how many and which ticks should be displayed, the latter to define what should be displayed. The documentation can be found here:

There are also corresponding functions for date/time scales:

Custom time formats can be defined using d3.timeFormat

Axis properties

This is a selection of commonly used properties, more can be found in the source code.

axis.tickLength([x])

Set the length of the x- or y-axis ticks. While not usually applied because the charts can be explored interactively, it can be useful to display long ticks for print.

  1. Set the tickLength property to a number
var yAxis = sszvis.axisY().scale(yPosScale).orient("right").tickLength(bounds.innerWidth); // <- Set to a number

X-axis

The x-axis covers the x-dimension, both placement and width

Horizontal Bar Chart
Loading the chart…

X-axis (Time)

This x-axis displays time values

Line Chart — Basic
Loading the chart…

X-axis (Ordinal)

This x-axis displays ordinal categories

Stacked Bar Chart
Loading the chart…

X-axis (Centered Title, Custom Highlight Ticks)

The x-axis title is centered because there are two y-axes. In addition, the ticks displayed on the bottom are customized, rather than using the default d3.scale.ticks. This is done to ensure that whichever value the user is hovering over is also displayed as a highlighted tick in the axis.

Line Chart — Two-Axis
Loading the chart…

X-axis (Pyramid)

This x-axis is specific to the population pyramid chart. It creates a two-sided axis that extends in the positive direction on either side of the center point.

Population Pyramid — Basic
Loading the chart…

Y-axis (With 0)

By default, sszvis y-axes don't show a label at 0. Since values go negative in this chart, this one does.

Grouped Bar Chart — Two Small
Loading the chart…

Y-axis (Ordinal)

This y-axis shows ordinal categories

Horizontal Bar Chart — Interactive
Loading the chart…

Multi-Line Axis

Sometimes, the axis labels are long enough that they will overlap their neighbors. In these cases, use the textWrap property. For bar charts, a good width for text wrapping is the width of a bar plus the space between bars.

Vertical Bar Chart
Loading the chart…

Slants (Diagonal - Top)

This x-axis (with a 'top' orientation) has a diagonal slant

Heat Table — Kreise
Loading the chart…

Slants (Diagonal)

This x-axis has a diagonal slant. Here are the guidelines for changing the slant of the axis:

  • Labels are always displayed horizontally, if there is enough space to show them clearly separate from each other.
  • If horizontal labels don't have enough space and overlap, they are displayed diagonally (45°).
  • If diagonal labels don't have enough space and overlap or touch the canvas area, they are displayed orthogonally (90°).
Grouped Bar Chart — Two Small
Loading the chart…

Contours

Contours are used to make labels stand out, especially when they are positioned above chart components. Contours should not be used on area charts.

Line Chart — Ordinal
Loading the chart…