View as Markdown

Charts

Chart

One Chart component with a series collection covering line, area, column, bar, scatter, bubble, financial, waterfall, histogram, box plot and Pareto series, with curves, stacks and data colors.

Chart lives in @salmonui/charts/chart (CSS: @salmonui/charts/chart/styles.css). It is one component with a series collection: mixed types combine freely in one chart.

import { Chart } from '@salmonui/charts/chart';
import '@salmonui/charts/chart/styles.css';

<Chart
  title="Sales"
  data={rows}
  series={[
    { type: 'column', xField: 'month', yField: 'north', name: 'North' },
    { type: 'line', xField: 'month', yField: 'south', name: 'South', curve: 'monotone', markers: true },
  ]}
/>;

Series can also be written as children, which compile to the same model (and render identically on the server):

import { Chart, ChartAxis, ChartSeries } from '@salmonui/charts/chart';

<Chart data={rows}>
  <ChartSeries type="line" xField="month" yField="north" />
  <ChartAxis direction="y" title="Units" />
</Chart>

Series types

type Covers Notes
'line' line, spline, step line, multicolored line curve, segments
'area' area, spline area, step area, range area, spline and step range area lowField + highField draw a range
'column', 'bar' column, bar, range column bar transposes; lowField + highField for ranges
'scatter', 'bubble' scatter, bubble markers.shape, sizeField, radius: [min, max]
'hilo', 'ohlc', 'candle' high-low, high-low-open-close, candlestick openField, highField, lowField, closeField; candles use the success / danger seeds, upColor, downColor, hollow; volumeField draws volume columns in the bottom fifth of the plot, in the candle colors, and adds the volume to the tooltip
'waterfall' waterfall totals, subtotals (indexes or a predicate), connectors
'histogram' histogram automatic bins or binWidth, normalCurve
'boxPlot' box and whisker yField holds an array per category; quartileMethod: 'exclusive' | 'inclusive' | 'normal', mean, outliers
'pareto' Pareto sorted columns plus the cumulative percent line on a generated secondary axis; pareto: { line, markers, color }

orientation="horizontal" transposes the whole chart, so bars combine with lines and every other series type.

Lines, steps and areas

Open demo

A Chart with a range area, a segmented line and an area on a second axis; switch the curve, the step position and the risers, and hide a series.

Temperature and rain. Range area, line and a segmented area

Area chart: Temperature and rain, 3 series, x from Jan to Dec. Average: 12 points, minimum 2, maximum 22, trending up. Rain: 12 points, minimum 40, maximum 96, trending up.

Temperature and rain
xLow to highAverageRain
Jan240
Feb3.377
Mar754
Apr1291
May1768
Jun20.745
Jul2282
Aug20.759
Sep1796
Oct1273
Nov750
Dec3.387

Curves and steps

series.curve is 'linear' (default), 'natural', 'monotone' (no overshoot), 'cardinal' with series.tension, 'clamped' or 'step'. Steps take stepPosition: 'start' | 'center' | 'end' and risers: false to draw the steps without vertical risers.

Stacks and groups

series.stack: true | 'percent' stacks series that share a value axis; positive and negative values stack separately and stackGroup keeps several stacks side by side. stackLabels draws the totals. Columns of different series sit side by side; grouping="overlap" overlaps them, series.group overlaps a subset, bandWidth (fraction of the category, or px above 1) and gap size them.

Columns, bars and stacks

Open demo

Column and bar series stacked, stacked to 100 % or grouped side by side or overlapping, with stack totals, band widths, range columns and a horizontal chart that combines bars with a line.

Band width
Units by region

Column chart: Units by region, 4 series, x from Q1 to Q4. North: 4 points, minimum 42, maximum 60, trending up. South: 4 points, minimum 30, maximum 39, trending up. West: 4 points, minimum 18, maximum 30, trending up. Returns: 4 points, minimum -8, maximum -4, flat.

Units by region
xNorthSouthWestReturns
Q1423018-4
Q2483722-6
Q3543226-8
Q4603930-4
Price range and target. Horizontal orientation: range bars combined with a line

Column chart: Price range and target, 2 series, x from Q1 to Q4. Target: 4 points, minimum 36, maximum 48, trending up.

Price range and target
xPrice rangeTarget
Q136
Q240
Q344
Q448

Appearance and data colors

name, hidden, order and opacity set a series' legend name, initial visibility, drawing order and opacity. Colors default to the derived palette slot (--salmon-chart-1 onward); series.color, palette, colorField and segment colors are data colors, used as given. lineStyle: 'solid' | 'dashed' | 'dotted' sets the stroke pattern. Segments color a line by value along segmentAxis. colorRanges colors points by y value range and feeds the range and gradient legends (see Chart elements).

Scatter, bubble and data colors

Open demo

Scatter series with marker shapes, a bubble chart sized by population and colored per point, and columns colored by value ranges with a series, point, range or gradient legend.

Height and weight

Scatter chart: Height and weight, 2 series, Height (cm) from 150 to 200. Group A: 20 points, minimum 48, maximum 80, trending up. Group B: 20 points, minimum 48, maximum 80, trending up.

Height and weight
Height (cm)Group AGroup B
1504863
1666260
1827675
1535368
1696766
1856480
1565857
1727271
1887048
1596462
1756176
1917553
1626968
1786665
1948059
1655773
1817170
1524864
1686361
1847775
Wealth and health

Bubble chart: Wealth and health, 1 series, GDP per capita (k$) from 0 to 60. Countries: 6 points, minimum 63, maximum 83, trending up.

Wealth and health
GDP per capita (k$)Countries
12Aland
24Borea
35Corin
48Dalvi
8Estra
56Fenn
Yield by day

Column chart: Yield by day, 1 series, x from Mon to Sun. Yield: 7 points, minimum 20, maximum 85, trending up.

Yield by day
xYield
Mon20
Tue61
Wed32
Thu73
Fri44
Sat85
Sun56

Financial series

Open demo

Candle, OHLC and high-low series over daily prices, with hollow candles and volume columns in the candle colors.

ACME daily prices

Candlestick chart: ACME daily prices. No data.

ACME daily prices
xACME
Jan 5O 100 H 101.5 L 98.8 C 100 V 1,200
Jan 6O 102.98 H 108.45 L 101.28 C 105.95 V 1,577
Jan 7O 105.84 H 109.34 L 102.87 C 105.07 V 1,954
Jan 8O 108.45 H 109.95 L 102.98 C 105.68 V 1,431
Jan 9O 110.73 H 114.71 L 109.53 C 112.21 V 1,808
Jan 10O 107.59 H 113.49 L 105.89 C 109.99 V 1,285
Jan 11O 108.98 H 110.48 L 104.68 C 106.88 V 1,662
Jan 12O 109.87 H 112.37 L 105.32 C 108.02 V 2,039
Jan 13O 110.27 H 116.35 L 109.07 C 112.85 V 1,516
Jan 14O 110.22 H 112.91 L 108.52 C 111.41 V 1,893
Jan 15O 104.79 H 107.29 L 99.7 C 101.9 V 1,370
Jan 16O 104.05 H 107.55 L 100.91 C 103.61 V 1,747
Jan 17O 103.13 H 107.63 L 101.93 C 106.13 V 1,224
Jan 18O 102.13 H 104.63 L 100.11 C 101.81 V 1,601
Jan 19O 101.19 H 104.69 L 96.08 C 98.28 V 1,978
Jan 20O 95.43 H 98 L 92.73 C 96.5 V 1,455
Jan 21O 94.95 H 100.08 L 93.75 C 97.58 V 1,832
Jan 22O 94.84 H 98.34 L 91.38 C 93.08 V 1,309
Jan 23O 95.18 H 96.68 L 90.79 C 92.99 V 1,686
Jan 24O 96.01 H 100.83 L 93.31 C 98.33 V 2,063
Jan 25O 92.33 H 97.42 L 91.13 C 93.92 V 1,540
Jan 26O 94.13 H 95.63 L 89.7 C 91.4 V 1,917
Jan 27O 96.36 H 98.86 L 93.27 C 95.47 V 1,394
Jan 28O 98.93 H 105.39 L 96.23 C 101.89 V 1,771
Jan 29O 101.76 H 103.39 L 100.56 C 101.89 V 1,248
Jan 30O 99.73 H 102.23 L 95.05 C 96.75 V 1,625
Jan 31O 102.72 H 106.87 L 100.52 C 103.37 V 2,002
Feb 1O 105.6 H 109.92 L 102.9 C 108.42 V 1,479
Feb 2O 108.26 H 110.76 L 105.68 C 106.88 V 1,856
Feb 3O 110.58 H 114.08 L 106.42 C 108.12 V 1,333

Error bars

series.errorBars: { kind, amount, direction, caps, axis } draws whiskers: kind is 'fixed', 'percent', 'standardDeviation', 'standardError' or 'custom' (plusField / minusField), direction 'both' | 'plus' | 'minus', and axis 'y' (default), 'x' (continuous x axes) or 'both'.

Waterfall, histogram, box plot, Pareto and error bars

Open demo

The statistical Chart series: a profit bridge with subtotals and totals, a histogram with a normal curve, box plots with three quartile methods, a Pareto chart and columns with five kinds of error bars.

Profit bridge

Waterfall chart: Profit bridge, 1 series, x from Revenue to Net profit. Amount: 7 points, minimum -180, maximum 420, trending down.

Profit bridge
xAmount
Revenue$420
Cost of sales-$180
Gross profit$240
Marketing-$60
R&D-$75
Other income$25
Net profit$130
Response times

Histogram chart: Response times, 1 series, x from 100 to 300. Requests: 200 points, minimum 119, maximum 337, trending down.

Response times
xRequests
0220
1249
2229
3292
4225
5298
6209
7266
8191
9217
10189
11179
12213
13172
14254
15195
16291
17230
18301
19256
20274
21263
22223
23253
24176
25242
26160
27241
28185
29251
30239
31261
32292
33258
34318
35238
36304
37211
38264
39197
40222
41210
42202
43250
44210
45297
46235
47325
48259
49316
50268
51272
52263
53216
54255
55180
56256
57184
58270
59224
60285
61278
62287
63316
64267
65321
66232
67295
68203
69256
70201
71229
72232
73225
74283
75239
76326
77257
78337
79265
80307
81259
82252
83251
84202
85253
86183
87269
88204
89292
90250
91302
92295
93288
94314
95250
96302
97208
98272
99187
100243
101202
102232
103248
104238
105302
106250
107332
108253
109322
110245
111276
112232
113220
114231
115184
116248
117184
118277
119216
120299
121258
122296
123286
124263
125287
126213
127267
128174
129242
130169
131229
132202
133231
134257
135239
136302
137239
138313
139225
140284
141206
142232
143197
144185
145210
146166
147242
148182
149277
150216
151290
152246
153268
154256
155219
156245
157167
158227
159140
160216
161155
162218
163202
164226
165256
166226
167286
168210
169277
170183
171236
172164
173188
174167
175157
176198
177156
178241
179179
180271
181206
182267
183220
184228
185216
186170
187204
188126
189197
190119
191202
192152
193214
194205
195219
196248
197204
198260
199173
Weekly hours per team

Box plot chart: Weekly hours per team. No data.

Weekly hours per team
xHours
Alphamin 30, Q1 30, median 30, Q3 37, max 37
Betamin 33, Q1 35, median 39, Q3 43, max 45
Gammamin 36, Q1 38, median 42, Q3 46, max 48
Deltamin 39, Q1 41, median 45, Q3 49, max 59
Defects by cause

Pareto chart: Defects by cause, 1 series, x from Scratches to Other. Defects: 6 points, minimum 5, maximum 46, trending down.

Defects by cause
xDefects
Scratches46
Missing screw27
Dent19
Misalignment12
Wrong part8
Other5
Effect by dose

Column chart: Effect by dose, 1 series, x from Placebo to 40 mg. Effect: 4 points, minimum 12, maximum 41, trending up.

Effect by dose
xEffect
Placebo12
10 mg21
20 mg34
40 mg41

Live data

data is reactive: a new array (for example the old one with a point appended and the oldest dropped) lays the chart out again, within 2 ms for a 1,000-point window (chart-perf.spec.ts). api.appendPoints(seriesId, points, { maxPoints }) streams points through the chart store without a React render of the parent; @salmonui/data live sources feed either.

Descriptions

series.description is appended to the chart summary and the accessible table caption, so screen readers hear what each series means; keyboard focus moves through the series in series order.

Live data and empty state

Open demo

Stream server load into one chart through reactive data and into another through api.appendPoints, clear the data to see the empty state, with series descriptions for screen readers.

Server load (reactive data)

Line chart: Server load (reactive data), 2 series, x from 0 to 50. CPU: 60 points, minimum 11, maximum 80, trending up. Memory: 60 points, minimum 52, maximum 68, trending down. CPU: CPU use of the web server in percent, sampled four times a second.. Memory: Memory use in percent..

Server load (reactive data). CPU: CPU use of the web server in percent, sampled four times a second.. Memory: Memory use in percent..
xCPUMemory
045%60%
158%61%
257%61%
349%62%
450%63%
564%64%
674%64%
769%65%
859%65%
961%66%
1074%66%
1180%67%
1271%67%
1360%67%
1462%68%
1572%68%
1673%68%
1760%68%
1849%68%
1951%68%
2060%68%
2157%68%
2242%67%
2331%67%
2436%67%
2543%66%
2638%66%
2723%65%
2816%64%
2924%64%
3032%63%
3126%63%
3213%62%
3311%61%
3422%60%
3531%60%
3625%59%
3716%58%
3819%58%
3933%57%
4041%56%
4136%56%
4229%55%
4335%54%
4451%54%
4558%53%
4651%53%
4746%53%
4854%52%
4969%52%
5072%52%
5163%52%
5258%52%
5367%52%
5479%52%
5577%52%
5665%53%
5759%53%
5868%53%
5976%54%
CPU (streamed with appendPoints)

Line chart: CPU (streamed with appendPoints), 1 series, x from 0 to 50. CPU: 60 points, minimum 11, maximum 80, trending up. CPU: The same CPU samples, streamed into the chart store..

CPU (streamed with appendPoints). CPU: The same CPU samples, streamed into the chart store..
xCPU
045
158
257
349
450
564
674
769
859
961
1074
1180
1271
1360
1462
1572
1673
1760
1849
1951
2060
2157
2242
2331
2436
2543
2638
2723
2816
2924
3032
3126
3213
3311
3422
3531
3625
3716
3819
3933
4041
4136
4229
4335
4451
4558
4651
4746
4854
4969
5072
5163
5258
5367
5479
5577
5665
5759
5868
5976

Polar and radar

import { Chart } from '@salmonui/charts/chart';
import { polar } from '@salmonui/charts/chart/features';

<Chart
  coordinate="radar"
  features={[polar]}
  xAxis={{ startAngle: 0 }}
  radius={0.9}
  data={wind}
  series={[
    { type: 'area', xField: 'direction', yField: 'speed' },
    { type: 'line', xField: 'direction', yField: 'gust', closed: false },
  ]}
/>;

coordinate: 'polar' | 'radar' maps x to the angle (clockwise from xAxis.startAngle, counterclockwise with xAxis.reversed) and y to the radius from the center (yAxis.reversed inverts it); radius (0..1) shrinks the circle. Polar charts draw circles, radar charts polygons between the spokes. Every polar and radar draw type is a series type: line, spline (curve), area, spline area, column (wedges, side by side per series), range column (lowField / highField), scatter, and the stacking variants with stack; lines and areas close back to the first point unless series.closed is false. Hover, focus, tooltips, selection and the accessible table work as on cartesian charts.

The polar layout is an opt-in feature: pass features={[polar]} from @salmonui/charts/chart/features. It renders on the server and the client alike; a chart without it never loads the code, draws the frame only and warns in development. features={[interactions]} bundles the zoom, pan, selection and drag code so it is ready on the first pointer event instead of loading after hydration.

Polar and radar charts

Open demo

Wind speed by direction on polar circles or radar polygons, drawn as lines, areas, wedges or points, stacked or not, from any start angle.

Start angle
Wind by direction

Column chart: Wind by direction, 3 series, x from N to NW. Calm: 8 points, minimum 2, maximum 4, trending up. Speed: 8 points, minimum 8, maximum 16, trending up. Gust: 8 points, minimum 14, maximum 24, trending up.

Wind by direction
xCalmSpeedGust
N2814
NE31321
E4917
SE21424
S31020
SW41516
W21123
NW31619

Field mapping

xField, yField, lowField, highField, openField, closeField, sizeField, colorField and tooltipField read plain records, including dotted paths such as 'price.close'; series.xAxis / series.yAxis bind a series to an axis by id. Per-series data overrides the chart data.

State, events and accessibility

Every interactive state is a controlled triad you can also leave uncontrolled: hiddenSeries / defaultHiddenSeries / onHiddenSeriesChange, selectedPoints / defaultSelectedPoints / onSelectedPointsChange and zoomRange / defaultZoomRange / onZoomRangeChange. Point and plot events (onPointClick, onPlotClick, ...) are covered in Chart interaction.

The chart is a <figure> named by title (or aria-label / aria-labelledby) with an automatic summary and a visually hidden data table; the plot is one tab stop with arrow-key navigation between points and the legend is a toolbar of toggle buttons (Chart interaction, "Keyboard").

The server renders the final SVG at the nominal size (width, else 600 px, and height, default 300) and the client relays out once after hydration if the measured size differs, so there are no hydration warnings; set locale and timeZone so the server and the browser format alike (Rendering and colors).

Features and templates

Features load from their props through lazy chunks; nothing is registered up front. Two features are explicit opt-in imports because they do not fit the Chart bundle budget:

import { polar, interactions } from '@salmonui/charts/chart/features';
import { technicalIndicators } from '@salmonui/charts/chart/indicators';

<Chart coordinate="polar" features={[polar]} /* ... */ />;
<Chart indicators={indicators} features={[technicalIndicators]} /* ... */ />;

Passing interactions is optional and makes zoom, pan and selection ready on the first pointer event.

Custom content comes from render props, never from HTML string templates: a string template would need HTML parsing and a sanitizer on the render path and could not be type-checked. Use a tooltip render, series.renderMarker, an axis renderLabel or renderEmpty:

<Chart tooltip={{ render: ({ header, points }) => <div>{header}: {points[0]?.yText}</div> }} /* ... */ />

Data, state and lifecycle

Data. Chart and the other visualizations take an array in data. Load the rows through a @salmonui/data source or your own fetch and pass the result; Kanban takes a @salmonui/data source directly.

Persistence. Components never write to localStorage, and server output never depends on client storage. To restore a view, store the controlled values from their change callbacks and pass them back: zoomRange, hiddenSeries and selectedPoints on Chart, value on gauges, path on TreeMap, view on GeoMap and columnOrder on Kanban.

Lifecycle. React owns the lifecycle and renders stay pure, so there are no load or loaded events that mutate the instance. Configure the chart through props, and run code that needs the rendered chart in an effect that reads the ref. There is no animation-complete callback.

Updates. Props are reactive: a changed prop re-renders only the affected part, so there is no refresh method. If you mutated data in place, pass a new array. series and axes are plain arrays with one source of truth, so there are no methods that add or remove series or axes: keep them in application state and update the arrays. For streaming, use api.appendPoints(seriesId, points).

WebMCP. WebMCP is a browser API proposal, so components do not register tools. Your application can register its own tools against the ref APIs.

3D and specialized charts

There are no 3D charts, because 3D perspective distorts length and area judgments and has poor accessibility.

  • 3D column and bar series. Use Chart with column and bar series, in any stacking mode.
  • Depth, rotation and tilt. Not supported. Scientific 3D plotting would be a separate WebGL product.
  • 3D pie and donut. Use PieChart, which has pie, donut, explode, labels, legend, tooltip, selection and export.
  • 3D legend, tooltip, labels, selection, export and print. Each is available on the flat Chart or PieChart.
  • Smith chart. Not built, because it serves radio-frequency engineering only; use a dedicated RF plotting library. coordinate accepts cartesian, polar and radar.
  • Chart wizard. There is no built-in chart wizard. Chart props are plain data, so an application can build a guided editor on top.

Every prop is listed in the API reference.