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:
- https://github.com/d3/d3-axis/blob/master/README.md#axis_ticks
- https://github.com/d3/d3-axis/blob/master/README.md#axis_tickValues
- https://github.com/d3/d3-axis/blob/master/README.md#axis_tickFormat
There are also corresponding functions for date/time scales:
- https://github.com/d3/d3-scale/blob/master/README.md#time_ticks
- https://github.com/d3/d3-scale/blob/master/README.md#time_tickFormat
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.
- Set the
tickLengthproperty to a number
var yAxis = sszvis.axisY().scale(yPosScale).orient("right").tickLength(bounds.innerWidth); // <- Set to a numberX-axis
The x-axis covers the x-dimension, both placement and width
X-axis (Time)
This x-axis displays time values
X-axis (Ordinal)
This x-axis displays ordinal categories
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.
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.
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.
Y-axis (Ordinal)
This y-axis shows ordinal categories
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.
Slants (Diagonal - Top)
This x-axis (with a 'top' orientation) has a diagonal slant
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°).
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.