Skip to content
Thrum

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-chart

This is a Pro component. The command works once your project has a licence key: set up Pro or see pricing.

Data shape

Type
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;
};
Sample
[
  { key: "checkout", name: "Checkout", values: [412, 398, null, 407] },
  { key: "search", name: "Search", values: [356, 349, 362, 340] },
]

Props

PropTypeDefaultDescription
labelsreadonly string[]RequiredNames of the points on the horizontal axis, oldest first.
seriesreadonly LineChartSeries[]RequiredUp 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.
labelstringRequiredWhat the chart measures. Read by screen readers and used as the table caption.
formatIntl.NumberFormatOptionsDefault compactHow values are written on the axis, in the readout and in the data table.
localestringDefault "en-US"Locale for number formatting. Fixed by default so the server and the browser print the same text.
yAxisbooleanDefault trueShow value lines and their labels. The axis fits the visible series and does not have to start at zero.
xAxisbooleanDefault trueShow point labels along the bottom. As many as fit are shown, always including the first and last.
legendbooleanDefault trueShow the legend. Each item is a button that hides or shows its series. It appears when there are two or more series.
hiddenreadonly string[]–Keys of the hidden series, when the parent controls them. Use it with onHiddenChange.
defaultHiddenreadonly 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.
soundbooleanDefault truePlay a tick as the cursor moves between points and a click when a legend item is pressed, if the visitor has sound on.
emptyLabelstringDefault "No data"Text shown when no visible series has a value.
classNamestring–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.
KeysAction
TabMove through the legend items, then to the plot. On the plot the cursor goes to the latest point.
Space / EnterOn a legend item: hide or show its series.
← →On the plot: move the cursor one point.
Home / EndOn the plot: jump to the first or last point.
EscHide the cursor.

Source

SourcePro

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. 1.0.1 · 2026-12-03Corners follow the project's --radius, down to square.
  2. 1.0.0 · 2026-12-02First release.

Loading index…

Keyboard shortcuts

/Ctrl KSearch components, docs and actions
?Show this list
AAppearance studio
SSound on or off
MFull or reduced motion
TTheme: auto, light, dark
GSurface: solid or frosted
BBackdrop photograph (under glass)
CCorner radius: square to round
RReplay the demo, on a component page
DDraw new data, on a component page
←→HomeEndMove the cursor in a focused chart
EscClose a dialog, or leave a chart cursor