Skip to content

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.

OptionDoes
min, maxfixed ends: the data cannot move them
suggestedMin, suggestedMaxends the axis reaches at least; data beyond them still widens it
stepgap between two ticks, such as 5
ticksabout how many ticks
formata function, or options: { currency: 'EUR', compact: true }
tickFormat(value, index) => string: the text of each tick, from code
gridfalse hides the grid of this axis; { dashed: true, color: '#ccc' } changes it
scalelog: powers of ten; zero and negative values have no place on it
titlethe 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:

ts
axes: [{ suggestedMin: 0, suggestedMax: 100 }]

min and max win over the suggested ends.

Ticks from code ​

ts
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:

ts
axes: [{ grid: false }, { side: 'right', grid: { dashed: true, color: '#94a3b8' } }]

Scatter and bubbles ​

ts
{
  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.

ts
{ type: 'scatter', center: true, data, xAxis: { suggestedMin: -40, suggestedMax: 40 } }