Line chart
Up to five metrics over the same period, drawn as lines on one plot. Use it to compare trends: latency per service, signups per plan. Legend items switch series on and off. For one metric where the amount matters, use the area chart.
Install
npx shadcn@latest add @thrum-pro/line-chartThis is a Pro component. The command works once your project has a licence key: set up Pro or see pricing.
Data shape
labels: readonly string[]; // one per point
type LineChartSeries = {
key: string; // stable id, used in hidden
name: string; // legend and readout
values: (number | null)[]; // one per label; null = gap
color?: string;
};[
{ key: "checkout", name: "Checkout", values: [412, 398, null, 407] },
{ key: "search", name: "Search", values: [356, 349, 362, 340] },
]Props
| Prop | Type | Default | Description |
|---|---|---|---|
labels | readonly string[] | Required | Names of the points on the horizontal axis, oldest first. |
series | readonly LineChartSeries[] | Required | Up to five lines. Colours follow the position in this list, so a series keeps its colour when another is hidden. A sixth series is drawn in a neutral colour. |
label | string | Required | What the chart measures. Read by screen readers and used as the table caption. |
format | Intl.NumberFormatOptions | Default compact | How values are written on the axis, in the readout and in the data table. |
locale | string | Default "en-US" | Locale for number formatting. Fixed by default so the server and the browser print the same text. |
yAxis | boolean | Default true | Show value lines and their labels. The axis fits the visible series and does not have to start at zero. |
xAxis | boolean | Default true | Show point labels along the bottom. As many as fit are shown, always including the first and last. |
legend | boolean | Default true | Show the legend. Each item is a button that hides or shows its series. It appears when there are two or more series. |
hidden | readonly string[] | – | Keys of the hidden series, when the parent controls them. Use it with onHiddenChange. |
defaultHidden | readonly string[] | Default [] | Keys of the series hidden at first, when the chart keeps the state itself. |
onHiddenChange | (hidden: string[]) => void | – | Called with the new list of hidden keys when a legend item is pressed. It is not called for the last visible series, which cannot be hidden. |
onActiveChange | (index: number | null) => void | – | Called with the index of the point under the cursor, or null when the cursor leaves. Use it to sync another chart or a table row. |
sound | boolean | Default true | Play a tick as the cursor moves between points and a click when a legend item is pressed, if the visitor has sound on. |
emptyLabel | string | Default "No data" | Text shown when no visible series has a value. |
className | string | – | Sets the size. The default is full width and 256 pixels tall, legend included. |
Motion and sound
Motion
- First draw: all lines are revealed together, left to right in 700 ms at constant speed.
- Hiding a series: its line fades out in 150 ms and the value axis re-fits to the series that remain. Their lines move to the new scale in 400 ms with no overshoot. Showing it again runs the same in reverse.
- New data with the same number of points: each line morphs to its new values in 400 ms. A different number of points switches at once.
- The cursor and its dots follow the pointer on a stiff spring.
- Reduced motion: the chart appears complete, and series, data and the cursor change instantly.
Sound
- A soft tick each time the cursor lands on a different point, at most one every 40 ms.
- A short click when a legend item hides or shows a series. Pressing the last visible series does nothing and makes no sound.
Sound is off until the visitor turns it on. Pass sound={false} to keep this component silent. How sound works
Accessibility
- The plot is one tab stop. It is exposed as a slider whose value text names the point and every visible series, for example “Tue: Checkout 412 ms, Search 356 ms”.
- Each legend item is a button with a pressed state: pressed means the series is drawn. A hidden series also shows an empty swatch and a struck-through name, so the state is never colour alone.
- The last visible series cannot be hidden. Its button is marked as disabled but stays focusable.
- A visually hidden table carries every value, one column per series. Hidden series stay in the table.
- In the readout a colour swatch sits beside each name. Names and values stay in the text colour.
| Keys | Action |
|---|---|
| Tab | Move through the legend items, then to the plot. On the plot the cursor goes to the latest point. |
| Space / Enter | On a legend item: hide or show its series. |
| ← → | On the plot: move the cursor one point. |
| Home / End | On the plot: jump to the first or last point. |
| Esc | Hide the cursor. |
Source
The source comes with Pro
TypeScript source · Copy-paste ready · MIT-compatible for client projects · Includes all dependencies
Files and dependencies
- Adds
components/ui/line-chart.tsx- Packages
motion- Brings along
- Chart foundationsMotion tokensSound engine
Changelog
- 1.0.1 · 2026-12-03Corners follow the project's --radius, down to square.
- 1.0.0 · 2026-12-02First release.