Charts
Chart elements
Titles, the legend toolbar with toggling and paging, data labels, last-value badges, inline series labels and annotations.
Title
title and subtitle are drawn at the top, start-aligned, and label the
<figure> through its figcaption. For a custom heading, omit
title and pass aria-labelledby with the heading's id, or aria-label;
they name the figure and the focusable plot and win over title and the
generated summary (aria-labelledby first). The title position is
fixed, which keeps a consistent reading order for assistive technology; for
a custom layout, render your own heading next to the chart and reference it
with aria-labelledby. Without any of them, the accessible name comes from
the generated data summary.
Legend
The legend appears with two or more series (legend forces it,
legend={false} hides it). It is drawn in the SVG and covered by an APG
Toolbar of toggle buttons: one tab stop, arrow keys between items (mirrored
in RTL), aria-pressed for the visible state, and the full series name as
the accessible name even when the drawn label is truncated.
Toggling proposes a change of the hiddenSeries / defaultHiddenSeries /
onHiddenSeriesChange(ids, event) triad; legend={{ toggle: false }} makes
the buttons plain. legend={{ overflow: 'page' }} pages a long
legend with previous / next buttons; legend.title and
legend.maxLabelWidth add a title and truncate labels with an ellipsis.
legend.position is 'auto', 'top', 'bottom', 'start' or 'end';
align: 'start' | 'center' | 'end' places the legend along that edge and
orientation: 'vertical' lays a top or bottom legend out in one column
(side legends are always one column, top and bottom legends wrap in rows by
default); columns fixes a grid and reverse flips the order.
legend.mode picks the items:
'series'(default): one toggle per series.'point': one item per point of the first visible series, in the point colors (colorField,colorRanges,getPointStyle).'range': one item percolorRangesentry (label, orfrom – to).'gradient': one key with thecolorRangescolors from the lowestfromto the highestto.
Point, range and gradient items are keys: they highlight on hover and focus
but do not toggle. colorRanges={[{ from, to, colors, label }]} colors every
point by its y value (several colors split the range into equal steps;
data colors).
legend.renderItem(item) returns custom content for an item (an icon, an
image, rich text): it is rendered inside the item's toolbar button, on the
server too, and replaces the drawn symbol and text; the accessible name
stays the series name. Custom items are HTML, so they are not part of the
exported SVG. For a legend image, render an <img> in
renderItem:
<Chart legend={{ renderItem: (item) => <><img src={`/icons/${item.id}.svg`} alt="" width={12} />{item.label}</> }} ... />
series.legendShape picks the drawn symbol per series: any marker shape
('circle', 'rectangle', 'triangle', 'diamond', 'star', ...) or
'seriesType' (default, a symbol for the series type).
Legend
Open demoA ten-series legend with positions, alignment, wrapping or paging, a title, truncated labels, legend shapes, custom items and a controlled list of hidden series.
Line chart: Visitors per city (thousands), 8 series, x from Jan to Jun. Amsterdam: 6 points, minimum 20, maximum 48, trending up. Barcelona: 6 points, minimum 22, maximum 45, trending up. Copenhagen: 6 points, minimum 26, maximum 49, trending up. Dublin: 6 points, minimum 21, maximum 44, trending up. Edinburgh: 6 points, minimum 25, maximum 48, trending up.
| x | Amsterdam | Barcelona | Copenhagen | Dublin | Edinburgh | Florence | Istanbul (European side) | Jerusalem |
|---|---|---|---|---|---|---|---|---|
| Jan | 20 | 31 | 42 | 23 | 34 | 45 | 48 | 29 |
| Feb | 27 | 38 | 49 | 30 | 41 | 22 | 25 | 36 |
| Mar | 34 | 45 | 26 | 37 | 48 | 29 | 32 | 43 |
| Apr | 41 | 22 | 33 | 44 | 25 | 36 | 39 | 20 |
| May | 48 | 29 | 40 | 21 | 32 | 43 | 46 | 27 |
| Jun | 25 | 36 | 47 | 28 | 39 | 20 | 23 | 34 |
hiddenSeries: Geneva, Helsinki
Data labels
series.labels (or { position, format, angle, showZero }) prints values
at the points; format is a preset ('n0', 'c2', 'p1'), a {value}
template or a function of the point.
labels.render(ctx) returns SVG content placed at the label anchor
(<text>, <tspan>s, an <image>), so custom labels stay in the drawing
and the export.
Smart labels: labels.overlap decides what a label that collides
with an earlier one does: 'hide', 'shiftY' / 'shiftX' (moved up to
three label sizes, inside the plot), 'rotate90', or 'none' (default).
One collision pass runs over every series that sets it, earlier series
first, with the text-width table (identical on the server).
labels.dedupe drops a label that repeats the previous label of its
series.
Markers
series.markers (true or { shape, size, filled }) draws a symbol per
point. series.renderMarker(ctx) returns SVG content centered on each point
instead, for images (<image href>) or any custom shape:
{ type: 'line', xField: 'month', yField: 'sales', markers: true, renderMarker: () => <image href="/pin.svg" x={-6} y={-6} width={12} height={12} /> }
Badges and inline labels
series.lastValue draws the last value at the plot edge and
series.inlineLabel the series name at the end of the line.
Annotations
annotations={[{ x, y, content }]} places any ReactNode at data
coordinates (units: 'data', default) or pixels (units: 'pixel'), on the
axes named by xAxis / yAxis.
Titles, data labels, markers and annotations
Open demoA titled column chart with positioned, rotated and templated data labels and annotations, and a line chart with marker shapes, custom SVG markers and labels, smart label overlap, last-value badges and inline series labels.
Column chart: Sign-ups, 1 series, x from Jan to Aug. Sign-ups: 8 points, minimum 0, maximum 179, trending up.
| x | Sign-ups |
|---|---|
| Jan | 120 |
| Feb | 167 |
| Mar | 124 |
| Apr | 0 |
| May | 128 |
| Jun | 175 |
| Jul | 132 |
| Aug | 179 |
Line chart: Price per kilo, 3 series, x from Jan to Aug. Coffee: 8 points, minimum 4.1, maximum 4.5, trending up. Tea: 8 points, minimum 4, maximum 4.4, trending up. Cocoa: 8 points, minimum 3.2, maximum 4.04, trending up.
| x | Coffee | Tea | Cocoa |
|---|---|---|---|
| Jan | $4.10 | $4.00 | $3.20 |
| Feb | $4.40 | $4.20 | $3.32 |
| Mar | $4.20 | $4.40 | $3.44 |
| Apr | $4.50 | $4.10 | $3.56 |
| May | $4.30 | $4.30 | $3.68 |
| Jun | $4.10 | $4.00 | $3.80 |
| Jul | $4.40 | $4.20 | $3.92 |
| Aug | $4.20 | $4.40 | $4.04 |
All of these are Chart props or series fields of
@salmonui/charts/chart (ChartLegendOptions, ChartDataLabels,
ChartMarkers, ChartAnnotation in the
API reference).