View as Markdown

Charts

Chart interaction

Tooltips, trackball, rectangle and wheel zoom, pan, point selection and the instance API, all driven by a per-chart store instead of React state.

Pointer, wheel and drag transients live in a per-chart store; React re-renders only the tooltip layer when the hovered point changes, never per pointer move. Committed changes go through controlled triads.

Tooltip

tooltip (or tooltip={{ format, header }}) shows the hovered point; series.tooltip: false opts a series out. tooltip.render(ctx) returns any ReactNode and runs only for the hovered point. ref.current.showTooltip({ seriesId, index }) and hideTooltip() open and close it from code.

tooltip.mode is 'point' (default), 'shared' (one box for every series at the x) or 'split' (one box per series, each at its own point). tooltip.position is 'nearest' (default: above the nearest point, found by binary search on the sorted x, no DOM hit-testing), 'pointer' (follows the pointer) or { x, y } (fixed, drawing px), and tooltip.offset is the gap in px. The tooltip, crosshair and hover marks are a lazy overlay chunk mounted after hydration; a pointer move costs one store write (the hover handler stays under 1 ms on 100,000 points, chart-perf.spec.ts).

Crosshair

crosshair draws lines at the pointer: lines: 'both' | 'x' | 'y', snap (to the nearest point), highlightCategory (shades the hovered category band), axisLabels (value boxes on the axes) and formatLabel(value, axisId) for their text. api.showCrosshair(point) takes a point ({ seriesId, index }) or data values ({ x, y }) and api.hideCrosshair() hides it; the position lives in the chart store.

Synchronized charts

<ChartSyncGroup tooltip crosshair zoom selection>
  <Chart data={a} selection ... />
  <Chart data={b} selection ... />
</ChartSyncGroup>

Charts in one ChartSyncGroup share the hovered x (tooltip and crosshair), the x zoom range and, between charts with selection, the selected point indices: a click in one chart proposes the same indices in the others through onSelectedPointsChange with reason: 'sync'. Each group instance has its own store.

Synchronized charts

Open demo

Two charts in a ChartSyncGroup share the hovered day (tooltip and crosshair), the x zoom range and the selected points; each kind of sync can be switched off.

Visitors

Area chart: Visitors, 1 series, x from 10 to 60. Visitors: 60 points, minimum 644, maximum 1,207, trending up.

Visitors
xVisitors
1800
2854
3905
4953
5995
61,030
71,057
81,074
91,082
101,079
111,067
121,046
131,017
14981
15940
16895
17849
18804
19761
20723
21691
22666
23650
24644
25647
26660
27683
28715
29754
30800
31850
32903
33957
341,010
351,060
361,104
371,142
381,173
391,194
401,206
411,207
421,199
431,182
441,156
451,122
461,083
471,040
48994
49948
50904
51864
52829
53801
54781
55771
56770
57779
58798
59826
60863
Orders

Column chart: Orders, 1 series, x from 10 to 60. Orders: 60 points, minimum 30, maximum 64, trending up.

Orders
xOrders
148
251
354
455
556
656
757
856
954
1052
1151
1248
1345
1442
1540
1637
1735
1833
1932
2031
2130
2230
2332
2433
2534
2637
2740
2843
2946
3049
3153
3255
3358
3460
3562
3664
3764
3864
3964
4063
4161
4259
4357
4454
4551
4648
4747
4844
4942
5040
5139
5238
5338
5438
5540
5642
5744
5846
5950
6053

Selected days: visitors none, orders none

Plot events and touch

onPlotClick(point, event) and onPlotPointerMove(point, event) fire anywhere on the plot (not only on points) with drawing coordinates and the data values under the pointer: { x, y, xValue, yValue }, xValue a category, Date or number of the x axis and yValue of the first y axis. onClick, onDoubleClick, onContextMenu and onPointerDown, onPointerUp, onPointerMove and onPointerLeave are DOM handlers on the chart root. StockChart and Gauge take the same set, TreeMap the click, double click, context menu and pointer move handlers. Sparkline and GeoMap keep their bundles small and take none: put the handlers on a wrapping element, where these events bubble.

Touch uses Pointer Events: a long press (500 ms) shows the tooltip of the nearest point and moving the finger cancels it; the plot sets touch-action: pan-y so the page still scrolls vertically, and none when zoom, pan, range or lasso selection or point drag need the gestures. Layout follows the container size, never device detection.

Trackball

crosshair={{ snap: true }} with tooltip={{ mode: 'shared' }} makes a trackball: the crosshair snaps to the nearest x, every series at that x is highlighted and listed in one tooltip.

Tooltip, crosshair and trackball

Open demo

Point, shared and split tooltips at the nearest point, the pointer or a fixed position, a custom tooltip render, crosshair lines with axis labels and category highlight, a snapping trackball, the tooltip and crosshair API, keyboard focus and touch long press.

Website visits

Line chart: Website visits, 3 series, x from Jan to Dec. Organic: 12 points, minimum 2,320, maximum 4,098, trending down. Paid: 12 points, minimum 1,800, maximum 3,030, trending up. Referral: 12 points, minimum 700, maximum 1,070, trending up.

Website visits
xOrganicPaidReferral
Jan3,2001,800700
Feb3,6312,210870
Mar3,9572,6201,040
Apr4,0983,030710
May4,0182,140880
Jun3,7392,5501,050
Jul3,3272,960720
Aug2,8842,070890
Sep2,5192,4801,060
Oct2,3202,890730
Nov2,3372,000900
Dec2,5652,4101,070

Zoom and pan

zoom turns on wheel zoom, rectangle selection zoom and pan; zoom={{ wheel, selection, pan, mode: 'x' | 'y' | 'xy' }} picks them. Shift + drag (or drag with selection: false) pans a zoomed chart; the pan frame stays in the store until release. Every committed step calls onZoomRangeChange(range, event) with event.reason 'wheel' | 'selection' | 'pan' | 'pinch' | 'keyboard' | 'toolbar' | 'reset'; a controlled chart vetoes by keeping its zoomRange; +, - and 0 zoom from the keyboard and api.resetZoom() resets. zoom.wheel and zoom.pinch (two touches, touch-action: none on the plot) zoom around the pointer or the midpoint of the fingers; the pinch frame stays in the store until the fingers lift; zoom.pinch: false turns pinch off. A wheel step on 100,000 points stays within a 16.7 ms frame at p95 (chart-perf.spec.ts). zoom.deferred moves only the drawn series during a pan and lays out once on release.

Lazy loading

onVisibleRangeChange({ axisId, range }) fires when a zoom or pan commits (never per drag frame), so an application fetches the rows of the visible range. createRangeSource from @salmonui/data does the fetching: it widens each request by half its span, caches loaded ranges, aborts superseded loads and exposes a snapshot for useSyncExternalStore:

import { createRangeSource } from '@salmonui/data';

const source = createRangeSource({ load: ([from, to], { signal }) => fetch(`/ticks?from=${from}&to=${to}`, { signal }).then((r) => r.json()) });

function LiveChart() {
  const { rows } = useSyncExternalStore(source.subscribe, source.getSnapshot, source.getSnapshot);
  return <Chart data={rows} zoom xAxis={{ scale: 'time', min: start, max: end }} onVisibleRangeChange={({ range }) => source.request(range)} series={[{ xField: 't', yField: 'v' }]} />;
}

There is no axis scrollbar; a linked RangeSelector navigator shows and moves the zoomed window (see Chart axes, "Axis scrollbar").

The drag, wheel and pinch code is a lazy chunk loaded after hydration when zoom, a range or lasso selection, or onPointChange is on; the plot gets data-interactive once it is ready.

import '@salmonui/navigation/toolbar/styles.css';
import '@salmonui/buttons/button/styles.css';

<Chart zoom={{ toolbar: ['zoom', 'pan', 'zoomIn', 'zoomOut', 'reset'], toolbarPosition: 'topEnd' }} {...props} />

zoom.toolbar (true for every tool, or a list) renders the zoom toolbar after hydration: Navigation's Toolbar with a ToggleButtonGroup for the drag tool (rubber-band zoom or pan) and buttons for zoom in, zoom out and reset (disabled while not zoomed). It loads from the public @salmonui/navigation/toolbar and @salmonui/buttons/button entries in a lazy chunk, so import their stylesheets; zoom.toolbarPosition is 'topEnd' (default), 'topStart', 'bottomEnd' or 'bottomStart', and text.zoomToolbar, zoomTool, zoomIn, zoomOut, pan and resetZoom localize the names.

Zoom, pan and the zoom toolbar

Open demo

A 2,000-point chart with wheel, pinch and rectangle zoom along x, y or both, pan, deferred pan, the zoom toolbar and a controlled zoom range whose changes and committed visible ranges are logged.

Sensor temperature

Line chart: Sensor temperature, 1 series, Hour from 400 to 900. Temperature: 2000 points, minimum 12, maximum 29.9, trending up.

Sensor temperature
HourTemperature
020 °C
121.1 °C
222.2 °C
323.2 °C
424.1 °C
524.9 °C
625.5 °C
723.6 °C
824 °C
924.2 °C
1024.3 °C
1124.3 °C
1224.3 °C
1324.4 °C
1422.1 °C
1522.3 °C
1622.5 °C
1722.9 °C
1823.4 °C
1924.1 °C
2024.9 °C
2123.5 °C
2224.4 °C
2325.4 °C
2426.5 °C
2527.4 °C
2628.3 °C
2729.1 °C
2827.4 °C
2927.9 °C
3028.3 °C
3128.5 °C
3228.6 °C
3328.5 °C
3428.4 °C
3525.9 °C
3625.7 °C
3725.6 °C
3825.5 °C
3925.5 °C
4025.7 °C
4126 °C
4224 °C
4324.6 °C
4425.2 °C
4525.9 °C
4626.7 °C
4727.5 °C
4828.2 °C
4926.6 °C
5027.2 °C
5127.6 °C
5228 °C
5328.1 °C
5428.1 °C
5528 °C
5625.4 °C
5725.1 °C
5824.7 °C
5924.3 °C
6024 °C
6123.6 °C
6223.4 °C
6321 °C
6421.1 °C
6521.3 °C
6621.6 °C
6722 °C
6822.6 °C
6923.2 °C
7021.5 °C
7122.1 °C
7222.7 °C
7323.1 °C
7423.5 °C
7523.7 °C
7623.8 °C
7721.4 °C
7821.3 °C
7921 °C
8020.6 °C
8120.1 °C
8219.7 °C
8319.3 °C
8416.6 °C
8516.3 °C
8616.2 °C
8716.2 °C
8816.4 °C
8916.7 °C
9017.1 °C
9115.3 °C
9216 °C
9316.7 °C
9417.3 °C
9518 °C
9618.6 °C
9719.1 °C
9817.1 °C
9917.3 °C
10017.4 °C
10117.4 °C
10217.3 °C
10317 °C
10416.8 °C
10514.1 °C
10613.9 °C
10713.7 °C
10813.5 °C
10913.6 °C
11013.7 °C
11114 °C
11212.2 °C
11312.8 °C
11413.5 °C
11514.4 °C
11615.2 °C
11716.2 °C
11817 °C
11915.5 °C
12016.3 °C
12116.9 °C
12217.4 °C
12317.8 °C
12418 °C
12518.1 °C
12615.8 °C
12715.8 °C
12815.7 °C
12915.7 °C
13015.7 °C
13115.8 °C
13216 °C
13314 °C
13414.5 °C
13515.1 °C
13615.9 °C
13716.8 °C
13817.8 °C
13918.9 °C
14017.7 °C
14118.7 °C
14219.8 °C
14320.7 °C
14421.5 °C
14522.2 °C
14622.8 °C
14720.8 °C
14821.1 °C
14921.3 °C
15021.4 °C
15121.4 °C
15221.5 °C
15321.6 °C
15419.4 °C
15519.6 °C
15620 °C
15720.5 °C
15821.2 °C
15922 °C
16022.9 °C
16121.6 °C
16222.6 °C
16323.7 °C
16424.8 °C
16525.8 °C
16626.8 °C
16727.6 °C
16825.9 °C
16926.4 °C
17026.8 °C
17127.1 °C
17227.2 °C
17327.2 °C
17427.1 °C
17524.7 °C
17624.7 °C
17724.7 °C
17824.8 °C
17925 °C
18025.3 °C
18125.8 °C
18224 °C
18324.7 °C
18425.5 °C
18526.4 °C
18627.3 °C
18728.2 °C
18829 °C
18927.5 °C
19028.1 °C
19128.6 °C
19228.9 °C
19329.1 °C
19429.2 °C
19529.1 °C
19626.6 °C
19726.3 °C
19826 °C
19925.7 °C
20025.5 °C
20125.3 °C
20225.2 °C
20322.9 °C
20423.1 °C
20523.5 °C
20623.9 °C
20724.5 °C
20825.1 °C
20925.8 °C
21024.2 °C
21124.8 °C
21225.4 °C
21325.8 °C
21426.2 °C
21526.4 °C
21626.4 °C
21724 °C
21823.7 °C
21923.4 °C
22023 °C
22122.5 °C
22222.1 °C
22321.7 °C
22419 °C
22518.8 °C
22618.7 °C
22718.8 °C
22819 °C
22919.4 °C
23019.8 °C
23118 °C
23218.6 °C
23319.3 °C
23419.9 °C
23520.4 °C
23620.9 °C
23721.3 °C
23819.2 °C
23919.2 °C
24019.2 °C
24119 °C
24218.7 °C
24318.4 °C
24418 °C
24515.3 °C
24614.9 °C
24714.7 °C
24814.5 °C
24914.5 °C
25014.6 °C
25114.9 °C
25213 °C
25313.6 °C
25414.3 °C
25515 °C
25615.8 °C
25716.6 °C
25817.3 °C
25915.7 °C
26016.2 °C
26116.7 °C
26217 °C
26317.2 °C
26417.2 °C
26517.2 °C
26614.7 °C
26714.6 °C
26814.4 °C
26914.3 °C
27014.2 °C
27114.3 °C
27214.4 °C
27312.4 °C
27412.9 °C
27513.5 °C
27614.3 °C
27715.2 °C
27816.2 °C
27917.2 °C
28015.8 °C
28116.8 °C
28217.8 °C
28318.6 °C
28419.3 °C
28519.8 °C
28620.3 °C
28718.2 °C
28818.4 °C
28918.5 °C
29018.5 °C
29118.6 °C
29218.6 °C
29318.7 °C
29416.5 °C
29516.8 °C
29617.3 °C
29717.9 °C
29818.6 °C
29919.5 °C
30020.5 °C
30119.2 °C
30220.3 °C
30321.4 °C
30422.5 °C
30523.5 °C
30624.5 °C
30725.3 °C
30823.6 °C
30924.1 °C
31024.4 °C
31124.7 °C
31224.8 °C
31324.9 °C
31424.9 °C
31522.6 °C
31622.6 °C
31722.8 °C
31823 °C
31923.3 °C
32023.8 °C
32124.5 °C
32222.9 °C
32323.8 °C
32424.7 °C
32525.7 °C
32626.7 °C
32727.7 °C
32828.6 °C
32927.1 °C
33027.8 °C
33128.3 °C
33228.7 °C
33328.9 °C
33429 °C
33529 °C
33626.5 °C
33726.4 °C
33826.2 °C
33926 °C
34025.9 °C
34125.9 °C
34226 °C
34323.9 °C
34424.3 °C
34524.8 °C
34625.4 °C
34726.1 °C
34826.9 °C
34927.7 °C
35026.1 °C
35126.8 °C
35227.4 °C
35327.9 °C
35428.2 °C
35528.4 °C
35628.4 °C
35726 °C
35825.8 °C
35925.5 °C
36025.1 °C
36124.7 °C
36224.3 °C
36324 °C
36421.4 °C
36521.3 °C
36621.3 °C
36721.5 °C
36821.8 °C
36922.2 °C
37022.7 °C
37121 °C
37221.6 °C
37322.2 °C
37422.8 °C
37523.3 °C
37623.7 °C
37724 °C
37821.7 °C
37921.7 °C
38021.6 °C
38121.3 °C
38220.9 °C
38320.5 °C
38420.1 °C
38517.3 °C
38616.9 °C
38716.6 °C
38816.5 °C
38916.5 °C
39016.6 °C
39116.9 °C
39215 °C
39315.5 °C
39416.1 °C
39516.8 °C
39617.5 °C
39718.2 °C
39818.8 °C
39916.9 °C
40017.3 °C
40117.6 °C
40217.8 °C
40317.8 °C
40417.6 °C
40517.4 °C
40614.8 °C
40714.6 °C
40814.3 °C
40914.1 °C
41013.9 °C
41113.9 °C
41214.1 °C
41312 °C
41412.5 °C
41513.1 °C
41613.8 °C
41714.6 °C
41815.5 °C
41916.4 °C
42015 °C
42115.8 °C
42216.6 °C
42317.2 °C
42417.8 °C
42518.2 °C
42618.4 °C
42716.3 °C
42816.3 °C
42916.3 °C
43016.2 °C
43116.2 °C
43216.2 °C
43316.2 °C
43414.1 °C
43514.4 °C
43614.9 °C
43715.5 °C
43816.3 °C
43917.2 °C
44018.1 °C
44116.9 °C
44218 °C
44319.1 °C
44420.1 °C
44521.1 °C
44621.9 °C
44722.6 °C
44820.9 °C
44921.3 °C
45021.6 °C
45121.8 °C
45221.9 °C
45322 °C
45422 °C
45519.8 °C
45619.9 °C
45720.1 °C
45820.5 °C
45921 °C
46021.6 °C
46122.4 °C
46220.9 °C
46321.9 °C
46422.9 °C
46524 °C
46625.1 °C
46726.1 °C
46827.1 °C
46925.6 °C
47026.3 °C
47126.9 °C
47227.3 °C
47327.5 °C
47427.7 °C
47527.7 °C
47625.3 °C
47725.2 °C
47825.2 °C
47925.2 °C
48025.2 °C
48125.4 °C
48225.7 °C
48323.8 °C
48424.3 °C
48525 °C
48625.8 °C
48726.6 °C
48827.5 °C
48928.4 °C
49026.9 °C
49127.7 °C
49228.4 °C
49328.9 °C
49429.3 °C
49529.5 °C
49629.5 °C
49727.1 °C
49827 °C
49926.7 °C
1500 more rows not shown

zoomRange.x: 400–900

    Selection

    selection (or selection={{ mode: 'point' | 'series', multiple }}) selects points by click or Enter; the triad is selectedPoints / defaultSelectedPoints / onSelectedPointsChange(points, event) with { seriesId, index } entries, and Ctrl / Cmd adds to the selection. Selected marks carry data-selected for styling; series under a legend hover carry data-highlighted and the others data-dimmed. mode: 'series' selects the whole series and mode: 'cluster' every series' point at the clicked index.

    selection={{ mode: 'range', axis: 'x' | 'y' | 'xy' }} selects the points inside a dragged rectangle (a band along x or y for one axis) and mode: 'lasso' the points inside a drawn polygon (point-in-polygon on the model's anchors, no DOM hit-testing). Both propose the points through onSelectedPointsChange with reason: 'range' | 'lasso' and call onRangeSelect({ ranges, points }, event) with the data range per axis.

    highlight: 'series' | 'point' | 'cluster' fades everything but the hovered series, point or index (data-faded, set on the marks without a React render), and legend.highlight dims the other series while a legend item is hovered or focused. onPointClick, onPointDoubleClick and onPointHover receive the point context { seriesId, index, datum, x, y, ... }.

    Editing points

    <Chart
      data={rows}
      series={[{ xField: 'month', yField: 'units', markers: true, editable: { min: 0, max: 100, step: 1 } }]}
      onPointChange={({ index, value }) => setRows((r) => r.map((d, i) => (i === index ? { ...d, units: value } : d)))}
    />

    series.editable lets the pointer drag a point's value; the preview is a store overlay and onPointChange({ seriesId, index, value }, event) fires once on release with the value clamped to min / max. With the plot focused, Up / Down (Left / Right in a horizontal chart) step the focused point by step (default a tenth of the tick interval, Shift for ten steps). Edits are proposals: the application updates data.

    Selection, highlight, point events and editing

    Open demo

    Point, series and cluster selection with a controlled selectedPoints list, hover highlight, styling hooks, point and plot events, range and lasso selection on a scatter chart, and a line whose points are edited by drag or keyboard.

    Sales by region

    Column chart: Sales by region, 3 series, x from Q1 to Q6. North: 6 points, minimum 40, maximum 55, trending up. South: 6 points, minimum 30, maximum 55, trending up. West: 6 points, minimum 22, maximum 37, trending up.

    Sales by region
    xNorthSouthWest
    Q1403022
    Q2534729
    Q3413436
    Q4545123
    Q5423830
    Q6555537

    selectedPoints: none

    Samples

    Scatter chart: Samples, 1 series, x from 0 to 80. Samples: 60 points, minimum 0, maximum 99, trending up.

    Samples
    xSamples
    00
    3761
    7422
    1183
    4844
    855
    2266
    5927
    9688
    3349
    7010
    771
    4432
    8193
    1854
    5515
    9276
    2937
    6698
    359
    4020
    7781
    1442
    513
    8864
    2525
    6286
    9947
    368
    7369
    1030
    4791
    8452
    2113
    5874
    9535
    3296
    6957
    618
    4379
    8040
    171
    5462
    9123
    2884
    6545
    26
    3967
    7628
    1389
    5050
    8711
    2472
    6133
    9894
    3555
    7216
    977
    4638
    8399
    Planned units (drag a point, or focus the plot and press Up / Down)

    Line chart: Planned units (drag a point, or focus the plot and press Up / Down), 1 series, x from Q1 to Q6. Units: 6 points, minimum 12, maximum 25, trending up.

    Planned units (drag a point, or focus the plot and press Up / Down)
    xUnits
    Q112
    Q218
    Q315
    Q422
    Q519
    Q625

      Keyboard

      The plot is one tab stop. Arrow keys move a virtual focus between points, Home / End jump to the ends, PageUp / PageDown switch series, Enter selects, Escape closes the tooltip; the focused point is announced through a polite live region. Every figure family (PieChart, FunnelChart, HeatMap, TreeMap, SankeyChart, GeoMap, Gauge, BulletChart) follows the same model: one tab stop, a virtual focus announced politely, legends as APG Toolbars; their accessibility trees are pinned as ARIA snapshots.

      There are no global shortcuts: a key like Alt+J collides with screen reader and browser keys, and intercepting Ctrl+P would hijack browser printing. Each visualization is one tab stop with the full keyboard model inside. For a shortcut, call api.focus() from your own key handler, and call api.print() from a button.

      Reference

      ChartApi (the ref), ChartTooltipOptions, ChartCrosshairOptions, ChartZoomOptions and ChartSyncGroupProps are in the API reference; the interactions feature is in @salmonui/charts/chart/features.