Live chart
A line for a value that keeps arriving: latency, throughput, queue length. Your code owns the samples and adds one every second or so; the chart slides to each new one and marks the newest point. For a fixed set of points with a reading cursor, use the area chart or the line chart.
Install
npx shadcn@latest add @thrum-pro/live-chartThis is a Pro component. The command works once your project has a licence key: set up Pro or see pricing.
Data shape
type LiveChartPoint = {
time: number; // milliseconds, for example Date.now()
value: number | null; // null = missed sample, leaves a gap
};[
{ time: 1796212800000, value: 212 },
{ time: 1796212801000, value: 230 },
{ time: 1796212802000, value: null },
{ time: 1796212803000, value: 224 },
]Props
| Prop | Type | Default | Description |
|---|---|---|---|
data | readonly LiveChartPoint[] | Required | Samples in order, oldest first. The parent owns the list and adds each new sample at the end. Samples older than the window can stay in the list; they are not drawn. |
label | string | Required | What the chart measures. Shown beside the latest value, read by screen readers and used as the table caption. |
window | number | Default 60000 | How much time the plot shows, in milliseconds, counted back from the newest sample. |
color | string | Default var(--chart-1) | Any CSS colour for the line and the marker. |
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 numbers and for the time labels. |
yAxis | boolean | Default true | Show value lines and their labels. The axis fits the samples in the window and the limit, with round ends. |
xAxis | boolean | Default true | Show the two ends of the time span along the bottom, for example “60s ago” and “now”. |
threshold | number | – | Draws a dashed limit line with its value. A signal plays when the newest value climbs from at or below the limit to above it. |
paused | boolean | Default false | Stops the slide and shows the word “Paused”. The chart steps to any sample that still arrives. To freeze the picture, also stop adding samples. |
hideLabel | boolean | Default false | Hide the label beside the latest reading when a surrounding panel already carries the heading. |
sound | boolean | Default true | Play the limit signal and cursor scrub ticks, if the visitor has sound on. |
emptyLabel | string | Default "No data" | Text shown when the window holds no value. |
className | string | – | Sets the size. The default is full width and 256 pixels tall, readout included. |
Motion and sound
Motion
- A new sample: the line slides left by one step at constant speed. The slide lasts as long as the time between the last two samples, so with a steady feed the line never stops and never jumps.
- The marker stays on the right edge and rides the line as the new segment comes in.
- The value axis has round ends and changes only when a value leaves it or the range shrinks to a rounder one. The line then settles on the new scale in 400 ms with no overshoot.
- Samples are joined with straight segments, so a part of the line that is already drawn never changes shape.
- Nothing runs between samples: when no data arrives, nothing moves.
- First draw: the line is revealed left to right in 700 ms, then the marker fades in.
- Paused or reduced motion: no slide and no reveal. Each new sample redraws the chart once.
Sound
- A two-tone signal when the newest value climbs over the limit. Nothing plays for the first reading, for a value that stays above the limit, or on the way down.
- A soft tick as the pointer or keyboard cursor moves between samples in the window.
Sound is off until the visitor turns it on. Pass sound={false} to keep this component silent. How sound works
Accessibility
- The plot is an image whose label states the latest value, the low and the high of the window, the limit and whether it is paused, for example “Latency: latest 212 ms, low 180 ms, high 347 ms, limit 300 ms”.
- It is not a live region: a value that changes every second would flood a screen reader. Readers ask for the value when they want it.
- A visually hidden table carries every sample in the window, with its age as the row header.
- A chart that updates for more than five seconds needs a pause control. Give the reader a button that sets paused and stops your feed.
| Keys | Action |
|---|---|
| Tab | Focus the plot. The inspection cursor opens on the newest sample in the window. |
| ← → | Step backwards or forwards through samples in the window. |
| Home / End | Jump to the oldest or newest sample in the window. |
| Esc | Hide the sample readout. |
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/live-chart.tsx- Packages
motion- Brings along
- Chart foundationsMotion tokensSound engine
Changelog
- 1.0.0 · 2026-12-02First release.