Chart
Shared chart pieces: the legend, the tooltip readout, the data table and the ChartFrame shell that AreaChart and BarChart draw into.
Preview
- Income
- Spending
- Savings
- Investments
- Web
- iOS
- Android
Installation
pnpm add @syntara/react @syntara/tokensimport { ChartLegend, ChartTooltip, ChartTable, ChartFrame, chartColor, chartTicks, chartLinePath, chartAreaPath, chartAxisFormat, formatChartValue, formatChartX, useChartSize } from '@syntara/react';Usage
import { ChartLegend } from '@syntara/react';
export function Legend() {
return <ChartLegend series={[{ key: 'income', label: 'Income' }, { key: 'spending', label: 'Spending' }]} />;
}Examples
Tooltip readout
The single-series value pill and the multi-series readout.
- Income$5,200
- Spending$4,100
Accessibility
No keyboard interaction of its own.
- ChartLegend is a list; swatches are aria-hidden and the names are text in text.subtle, never in the series colour.
- ChartTooltip is presentational; ChartFrame renders it aria-hidden because the focused option already carries the same values.
- ChartTable is a real <table> with a caption, column headers and row headers. It is visually hidden by default so every chart has a screen-reader equivalent.
- ChartFrame's keyboard model (ListBox, arrows, Home/End, Escape) is documented on Area Chart and Bar Chart.
Guidelines
Do
- Show a legend for two or more series; skip it for one (the title says what's plotted).
- Use chartColor(i) for custom marks so they follow the brand's solved palette.
Don’t
- Don't colour legend or readout text with the series colour.
- Don't add a fifth palette slot; chartColor repeats after 4.
API reference
ChartLegend
seriesRequiredChartSeries[]Series in palette order; each gets --syntara-chart-<n> unless it sets color.
shapesquaredefaultline
Mirror the mark: square for areas and bars, line for lines.
ChartTooltip
titleRequiredstringThe x value, formatted.
rowsRequired{ key; label; value; color }[]One row per series. One row renders a pill with the value first.
shapelinedefaultsquare
Key shape. Tooltips key with a short stroke.
ChartTable
captionRequiredstringThe table's name (the chart's).
series / rows / xLabelRequiredChartSeries[] / { x; values }[] / stringColumns, formatted rows and the first column's header.
isVisiblebooleanShows the table instead of hiding it visually.
Default
false
ChartFrame
count / mode / domain / ticks / marks / active / anchorY / tooltipRequiredsee chart.tsxThe low-level shell: axes, grid, SVG, ListBox hit layer, readout, legend and table. Build new chart types on it; marks() gets physical (RTL-mirrored) coordinates.
Tokens
The semantic tokens this component reads, grouped by what they control. Swatches show this site’s theme; change a tenant’s brand and the component follows with no code change.
- Colour6
text.defaulttext.subtleborder.defaultborder.subtlesurface.raisedfocus.ring- Type8
font.bodyfont.size.xsfont.size.smfont.size.mdfont.tracking.xsfont.tracking.smfont.weight.semiboldfont.weight.medium- Space and size5
space.1space.2space.3space.4space.16- Shape3
radius.containerradius.fieldradius.pill- Depth3
hairlineshadow.overlayshadow.highlight- Motion4
motion.duration.fastmotion.duration.normalmotion.easingmotion.easingOut- Other6
chart.1chart.2chart.3chart.4chart.gridchart.axis