Skip to main content

Axis

When composing charts with VictoryChart, axes will be automatically added to your chart.

Optionally, you also can directly configure the axes using the VictoryAxis and VictoryPolarAxis components by following this guide.

VictoryAxis

Creates linear independent and dependent axes.

info

See the full API for VictoryAxis for more details.


Basic

The VictoryAxis component can be used to render a basic axis.

Live View
Loading...
Live Editor

Axis - Single

The crossAxis prop can be used to render a horizontal axis, and the dependentAxis prop can be used to render a vertical axis.

Live View
Loading...
Live Editor

Axis - Tick Values

You can specify the specific tick values you would like to display on the axis using the tickValues prop.

Live View
Loading...
Live Editor

Axis - Tick Label Format

Use the tickFormat prop to customize axis labels. This prop can be given as an array of strings, or as a function that returns a string.

caution

VictoryChart automatically applies "smart" formatting to an axis for dates. When using a custom VictoryAxis or VictoryPolarAxis, you will need to format the tick values and labels manually as shown below.

Live View
Loading...
Live Editor

Time formats using d3-time

To replicate the behaviour of automatically formatting times in VictoryChart, you can use d3-scale to format the tick values and labels.

Live View
Loading...
Live Editor

Axis - Offset Position

You can offset the position of the axis using the offsetX and offsetY props.

Live View
Loading...
Live Editor

Axis - Orientation

The axis orientation can be set to top, bottom, left, or right using the orientation prop.

Live View
Loading...
Live Editor

Axis - Labels

The axis supports labels using the label prop.

Live View
Loading...
Live Editor

Axis - Multiple

Multiple axes can be added to a chart by nesting VictoryAxis components within VictoryChart.

info

The domain is shared between all dependent axes, so you need to normalize the data to fit the domain of each axis.

Live View
Loading...
Live Editor

Axis - Dependent

Dependent axes can be aligned to their corresponding data points by setting the axisValue prop.

Live View
Loading...
Live Editor

Axis - Small Values

When a dataset only has a single value, or when all values on an axis have the same value, the single-point domain for that axis will be converted to a two-point domain. Victory does this by offsetting the domain value by a very small number. To solve this, you will need to manually set sensible defaults on the domain of your chart.

Live View
Loading...
Live Editor

Axis - Common Label Problems

Long axis labels can be problematic. There are several ways to address the issue. The best solution will depend on the specific requirements of your project. The following examples demonstrate:

info

Using padding properties can help to adjust the position of the axis labels.

Live View
Loading...
Live Editor
info

Splitting the labels onto multiple lines can help to make the labels more readable.

Live View
Loading...
Live Editor
info

Using angled labels can help to make the labels more readable.

Live View
Loading...
Live Editor
info

Fixing axis label and tick label overlap using the style prop.

Live View
Loading...
Live Editor

VictoryPolarAxis

Creates a circular axis for a chart.

info

See the full API for VictoryPolarAxis for more details.


Basic

The VictoryPolarAxis component can be used to render a basic axis for polar charts.

Live View
Loading...
Live Editor

Axis - Angle

The dependent axis can be rendered at different angles.

Live View
Loading...
Live Editor

Axis - Labels

The label placement can be adjusted by using the labelPlacement prop.

Live View
Loading...
Live Editor

Axis - Half Circle

The polar axis can also be rendered in a confined set of angles. When VictoryPolarAxis is a child of VictoryChart, the startAngle and endAngle props will be set by the domain data.

Live View
Loading...
Live Editor