View as Markdown

Charts

Chart axes

Linear, logarithmic, time, category and time-category axes with nice ticks, calendar-aware time ticks, ranges, multiple axes, label overlap strategies, edge labels and zoom ranges.

Axes are xAxis, yAxis and any number of extra axes (each with an id and a direction); a series picks its axes with series.xAxis / series.yAxis, and axis.position: 'end' opposes an axis. Every axis option below is a field of xAxis, yAxis, an axes entry or a ChartAxis child of Chart (@salmonui/charts/chart).

Panes

panes splits the plot into rows and columns; an axis picks its pane with axis.pane, and its series follow it:

<Chart
  panes={{ rows: ['70%', '30%'] }}
  axes={[{ id: 'volume', direction: 'y', pane: { row: 1 }, title: 'Volume' }]}
  series={[
    { type: 'line', xField: 'date', yField: 'close' },
    { type: 'column', xField: 'date', yField: 'volume', yAxis: 'volume' },
  ]}
/>

Axes on the left or right take a row (pane.row), axes on the top or bottom a column (pane.column); pane.span covers several. A size is px, 'n%' of the plot or { size }; unsized panes share the rest equally. Axes of one side in different panes share one slot instead of stacking outward, and each axis draws its line and title along its own pane.

Scales

  • scale: 'linear' (the default for numbers) uses 1-2-5 nice ticks.
  • scale: 'time' (the default for Date values and ISO date strings) ticks on calendar boundaries: local midnight, the first of a month, ... in the chart timeZone. axis.interval: { unit, step } fixes the interval and axis.format takes a date skeleton ('yMMMd') or Intl.DateTimeFormatOptions. Without timeZone, server and client render in UTC.
  • scale: 'category' (the default for strings) and scale: 'timeCategory' (dates without gaps) place one band per value; axis.labelPlacement: 'between' | 'on' puts labels between ticks or on them, and axis.indexed: true gives every point index its own band, so repeated categories stay separate.
  • scale: 'log' with axis.base.

Axis scales and ranges

Open demo

Time and time-category axes with calendar intervals, linear and log value axes, an indexed category axis with label placement, and axis ranges with includeZero, padding, min, max, interval and tickCount.

Closing price

Line chart: Closing price, 1 series, x from Mar 2 to Mar 30. Close: 22 points, minimum 180, maximum 208.88, trending up.

Closing price
xClose
Mar 2$180
Mar 3$185
Mar 4$189
Mar 5$193
Mar 6$196
Mar 9$197
Mar 10$197
Mar 11$196
Mar 12$193
Mar 13$191
Mar 16$188
Mar 17$185
Mar 18$183
Mar 19$182
Mar 20$182
Mar 23$183
Mar 24$186
Mar 25$190
Mar 26$195
Mar 27$200
Mar 30$204
Mar 31$209
Users per year

Line chart: Users per year, 1 series, x from 2016 to 2025. Users: 10 points, minimum 30, maximum 79,254, trending up.

Users per year
xUsers
201630
201772
2018173
2019415
2020995
20212,389
20225,733
202313,759
202433,023
202579,254
Output per shift

Column chart: Output per shift, 1 series, x from Mon to Tue. Output: 5 points, minimum 39, maximum 51, trending up.

Output per shift
xOutput
Mon42
Tue47
Wed51
Mon39
Tue44

Ranges

axis.min, axis.max, axis.interval (numeric step), axis.tickCount, axis.includeZero and axis.padding: 'auto' | 'none' | 'normal' | 'additional' | 'round' replace minimum, maximum, interval, desiredIntervals, startFromZero and rangePadding.

Labels

axis.labelOverlap resolves crowded labels: 'hide' (keep every n-th), 'trim', 'wrap', 'stagger', 'rotate45' or 'rotate90', and axis.labelAngle sets a fixed rotation. Widths come from a deterministic text-width table, so server and client agree without measuring text. axis.edgeLabels: 'hide' | 'shift' keeps the first and last label inside the chart.

axis.labelPosition and axis.tickPosition ('inside' | 'outside') put the labels and the tick marks inside or outside the plot independently, and axis.plotOffset (px) pads both ends of the axis. axis.ticks: false, axis.line: false, axis.hidden, axis.gridLines and axis.minorTicks toggle the parts of an axis; axis.title with axis.titleAngle (degrees) names it. axis.format takes a preset ('n1', 'c0', 'p0'), a {value} template or Intl options, axis.formatLabel(value) returns the text, and axis.renderLabel(ctx) returns SVG text content (a string or <tspan>s) for a tick.

Formats use the same grammar and output as Data Grid column.format: presets ('n2', 'c2', 'p1'), Intl.NumberFormatOptions / Intl.DateTimeFormatOptions and date skeletons ('yMMMd', 'Hm'), in the chart locale and timeZone. There is no catalog-wide locale context, so locale is a prop; set it so the server and the client format alike. onAxisLabelClick({ axisId, value, text, index }, event) reports a click on a tick label, and axis.domain(computed) adjusts the computed range.

<Chart
  data={sales}
  xAxis={{
    labelGroups: [
      { levels: [{ from: 'Jan', to: 'Mar', label: 'Q1' }, { from: 'Apr', to: 'Jun', label: 'Q2' }] },
      { levels: [{ from: 'Jan', to: 'Jun', label: 'H1' }], border: 'brace' },
    ],
  }}
  onAxisLabelGroupClick={({ label }) => console.log(label)}
  series={[{ type: 'column', xField: 'month', yField: 'north' }]}
/>

axis.labelGroups draws multi-level labels: one row per group (a column on a vertical axis), one cell per level from a category (or value) to another, with border: 'rectangle' | 'brace' | 'curlyBrace' | 'none' | 'noTop' | 'noTopBottom'; onAxisLabelGroupClick reports a click on a cell.

Axis labels, formats and groups

Open demo

Crowded category labels resolved by hiding, trimming, wrapping, staggering or rotating; edge labels; inside labels and ticks; label formats, functions and SVG content; multi-level label groups; label clicks and locales.

Units by product

Column chart: Units by product, 1 series, x from Espresso machine to Scale with timer. Units: 8 points, minimum 120, maximum 245, trending up.

Units by product
xUnits
Espresso machine120
Milk frother173
Burr grinder226
Kettle with thermometer139
Pour-over dripper192
Cold brew jar245
Tamper158
Scale with timer211
Revenue

Area chart: Revenue, 1 series, x from Jan to Dec. Revenue: 12 points, minimum 1,200,000, maximum 1,763,719, trending up.

Revenue
xRevenue
Jan€1.2M
Feb€1.4M
Mar€1.6M
Apr€1.7M
May€1.8M
Jun€1.7M
Jul€1.6M
Aug€1.4M
Sep€1.3M
Oct€1.3M
Nov€1.3M
Dec€1.5M

Clicked: nothing yet

Crossing and bands

axis.crossAt: { value, axis } draws the axis line where the crossing axis (default: the primary axis of the other direction) has value; the labels stay at the plot edge unless axis.labelsAtCross moves them with the line. axis.reversed inverts an axis. axis.bands: [{ from, to, every, until, layer, label, color, crossFrom, crossTo }] shades ranges behind or over the series, repeating with every, and crossFrom / crossTo limit a band to a segment of the crossing axis; axis.lines draws labelled value lines.

Multiple axes, panes, crossing and bands

Open demo

A chart with three value axes, a pane for one of them, grid lines and minor ticks, axis titles, value bands and lines, and a second chart whose axes cross at zero and can be reversed.

Plant output

Column chart: Plant output, 3 series, x from Jan to Dec. Output: 12 points, minimum 724, maximum 1,080, trending down. Temperature: 12 points, minimum 5, maximum 23, trending up. Defects: 12 points, minimum 3, maximum 8, trending up.

Plant output
xOutputTemperatureDefects
Jan90053
Feb98664
Mar1,051105
Apr1,080146
May1,064197
Jun1,008228
Jul925233
Aug837224
Sep764195
Oct724146
Nov727107
Dec77368
Axes crossing at zero

Line chart: Axes crossing at zero, 1 series, x from -10 to 10. y: 21 points, minimum -7, maximum 7, trending up.

Axes crossing at zero
xy
-10-5
-9-0
-83
-75
-67
-57
-46
-35
-24
-12
00
1-2
2-4
3-5
4-6
5-7
6-7
7-5
8-3
90
105

Zoom range

The zoom range is a controlled triad: zoomRange / defaultZoomRange / onZoomRangeChange, keyed by axis id in data units ({ x: [start, end] }). Ticks are recomputed for the visible range. onVisibleRangeChange({ axisId, range }) fires once per committed change of a continuous axis (never per drag frame), the hook for loading the data of the visible range from the application or a @salmonui/data source. See Chart interaction.

The zoom range demo is on Chart interaction. Every axis field is listed under ChartAxisOptions in the API reference.

Axis scrollbar

There is no axis scrollbar, because it does not fit the Chart bundle budget and its job is already covered: a zoomed chart pans by drag, wheel and keyboard and through the zoom toolbar. To see and move the zoomed window, link a RangeSelector:

const [zoom, setZoom] = useState<ChartZoomRange>({ x: [0, 100] });

<Chart zoom zoomRange={zoom} onZoomRangeChange={(range) => setZoom(range)} /* ... */ />
<RangeSelector value={zoom.x} onValueCommit={(x) => setZoom({ x })} /* ... */ />

Run code that reacts to scrolling in onZoomRangeChange.