Axes
The value axes of xy charts are listed in axes (the first one is the default axis, on the left). scatter charts, bubbles included, take xAxis and yAxis. Every one of them reads the same options.
| Option | Does |
|---|---|
min, max | fixed ends: the data cannot move them |
suggestedMin, suggestedMax | ends the axis reaches at least; data beyond them still widens it |
step | gap between two ticks, such as 5 |
ticks | about how many ticks |
format | a function, or options: { currency: 'EUR', compact: true } |
tickFormat | (value, index) => string: the text of each tick, from code |
grid | false hides the grid of this axis; { dashed: true, color: '#ccc' } changes it |
scale | log: powers of ten; zero and negative values have no place on it |
title | the name of the axis |
step and ticks round the range to the step; with min and max set, the ticks start at the first multiple of the step. A step that would write more than 200 ticks is ignored. A log axis has its ticks at the powers of ten, whatever step and ticks say.
A suggested range
A score out of 100 that only reached 64 so far still shows the whole scale; a score of 130 would widen it:
axes: [{ suggestedMin: 0, suggestedMax: 100 }]min and max win over the suggested ends.
Ticks from code
axes: [
{ step: 1000, tickFormat: (value, index) => (index === 0 ? '' : `${value / 1000} k`) },
{ side: 'right', format: { percent: true }, grid: false },
]tickFormat writes the ticks only; tooltips keep the format of the chart.
Grid of each axis
The first axis draws the grid by default, following grid of the chart (false, 'dashed'). Each axis can draw its own:
axes: [{ grid: false }, { side: 'right', grid: { dashed: true, color: '#94a3b8' } }]Scatter and bubbles
{
type: 'scatter',
data,
xAxis: { min: 0, step: 10, title: 'Price' },
yAxis: { suggestedMax: 100, format: { compact: true }, grid: { dashed: true } },
}xAxis.title and yAxis.title replace xLabel and yLabel when both are given.
Axes crossing at zero
center: true draws the two axes through zero, inside the drawing, with their ticks beside them: a plane of gains and losses, of four quadrants. When zero is out of the range, the axis stays at the nearest end.
{ type: 'scatter', center: true, data, xAxis: { suggestedMin: -40, suggestedMax: 40 } }