Skip to content

Real-Time Line Chart for React

A real-time React line chart: each new sample glides in from the right while the time axis slides under it. Pass data as readonly ChartRow[]: samples so far, oldest first: { time, …values }.

npx shadcn@latest add https://lokendra-builds.github.io/sheenui/r/streaming-chart.json

web-01

Live
Use left and right arrow keys to read recent values; the view holds still while you read.

  • StreamingChart
  • StreamingTable
  • useLiveData
  • useStreamingData
  • defaultStreamingChartLabels
  • +3 more

Two series, one sample a second

useStreamingData calls your function every second and keeps a rolling buffer; the chart and its table both read it. Call it in the small component that renders the card, so each sample re-renders only that card. Hover, tap or arrow through the line to hold the view and read values. Pause stops the view; data keeps arriving and Resume glides to the present.

web-01

us-east-1 · last 60 seconds

Live

Files to copy

17 folders · 34 files · 4 packages
From theme/src/
  • components/charts/{streaming-chart.tsx, category-bar.tsx, chart-export-menu.tsx, chart-export.ts, chart-figure.tsx, chart-fit.tsx, chart-icons.tsx, chart-parts.tsx, chart-patterns.tsx, chart-pointer.tsx, chart-tip.tsx, chart-utils.ts, heatmap.tsx, streamgraph.tsx}
  • components/button/
  • components/charts/category-bar/
  • components/charts/chart-parts/
  • components/charts/heatmap/
  • components/charts/streamgraph/
  • components/charts/streaming-chart/
  • components/drawer/parts/sheet.tsx
  • components/kbd/
  • components/menu/
  • components/skeleton/
  • components/spinner/
  • components/status-icons/
  • hooks/{use-controllable.ts, use-direction.ts, use-intersection.ts, use-latest.ts, use-magnetic.ts, use-media-query.ts, use-preferences.ts}
  • motion/{gate.ts, tokens.ts}
  • lib/{cn.ts, csv.ts, form.ts, glide-highlight.tsx, heading.ts, math.ts, popup-a11y.ts, popup-motion.ts, state-light.tsx, warn-once.ts}
  • styles/
shadcn CLI
npx shadcn@latest add https://lokendra-builds.github.io/sheenui/r/streaming-chart.jsonRegistry item: streaming-chart. The styles need the Tailwind v4 glass UI setup.
Packages
pnpm add @base-ui/react clsx motion tailwind-merge

Next.js: samples here pass functions (formatters, seriesLegend, a dashboard's load), so put them in a file that starts with "use client".

Fast feed with a zero baseline

Two samples a second, 40 seconds in view, the axis anchored at zero. Push your own rows (from a socket, say) and the chart animates them the same way.

Edge requests

All regions, requests per second

Live

Props

PropTypeDefaultDescription
data (required)readonly ChartRow[]NoneSamples so far, oldest first: { time, …values }. Append rows as they arrive (or use useStreamingData).
indexstring"time"Key of the timestamp (ms) in each row.
series (required)readonly ChartSeries[]NoneUp to 4 lines, each with a fixed color slot.
ratenumber1000Expected ms between samples. The view trails the newest sample by this much, so points glide in.
windownumber60How much time is in view, in samples.
pausedbooleanNonePause the view (controlled). Data keeps arriving; resuming glides to the present.
defaultPausedbooleanfalseStarts in the paused state (uncontrolled).
onPausedChange((paused: boolean) => void)NoneCalled with the new paused state when the user pauses or resumes (controlled paused).
areabooleantrueFill under each line with a fading wash.
zerobooleanfalseKeep zero on the value axis.
heightnumber240Sets the height of the plot in px.
format((n: number) => string)formatCompact in localeFormats a value for the axis, tooltip and data table: takes the number, returns the text shown.
formatTime((time: Date) => string)"2:05:09 PM" (or "14:05:09") in localeFormats a timestamp as text.
localestringthe browser'sBCP 47 locale of the default formats.
timeZonestringthe viewer'sIANA time zone of the default time format, e.g. "UTC".
emptyStateReactNodeNoneShown before the first sample arrives.
labelsPartial<StreamingChartLabels>defaultStreamingChartLabelsEvery other string, for translation: labels={{ instructions: "…" }}; omitted keys keep the English of defaultStreamingChartLabels. All 8 keys of StreamingChartLabels are listed in the key table under the props table.
aria-label (required)stringNoneAccessible summary of what the chart shows.
classNamestringNoneAdds extra classes to the outer element.
StreamingChartLabels keys and English defaults (8)
Pass any key in labels; the rest keep the defaults of defaultStreamingChartLabels.
KeyEnglish default
instructionsUse left and right arrow keys to read recent values; the view holds still while you read.
liveLive
pausedPaused
holdingHolding
pausePause
resumeResume
waitingWaiting for data…
timeTime

useStreamingData(source, options)

PropTypeDefaultDescription
source(time, index) => number | Record<string, number>NoneCalled every rate ms for the next sample.
options.ratenumber1000Sets the number of milliseconds between two samples.
options.historynumber60Samples generated for the past at mount, so the chart starts full.
options.capacitynumber240Keeps this many samples; older ones drop off.
options.index / valueKeystring"time" / "value"Keys of the timestamp, and of the value when source returns a number.
options.enabledbooleantrueSet it to false to stop sampling.
options.startAtnumberDate.now()Time of the newest sample on the first render. Pass a fixed time on prerendered pages (the server's and the browser's history must match); right after mount the history is rebuilt to end now.
options.pauseWhenHiddenbooleantrueNo timer while the tab is hidden; back on the tab the missed samples are filled in, so the line stays continuous.
options.idlebooleanfalseRest without losing time (e.g. pass !inView): no timer while true, then the missed samples are filled in.

StreamingTable props

PropTypeDefaultDescription
data (required)readonly ChartRow[]NoneSamples so far, oldest first: { time, …values }. Append rows as they arrive (or use useStreamingData).
format((n: number) => string)formatCompact in localeFormats a value for the axis, tooltip and data table: takes the number, returns the text shown.
labelsPartial<StreamingChartLabels>defaultStreamingChartLabelsEvery other string, for translation: labels={{ instructions: "…" }}; omitted keys keep the English of defaultStreamingChartLabels. All 8 keys of StreamingChartLabels are listed in the key table under the props table.
localestring"en"BCP 47 locale of the default formats.
indexstring"time"Key of the timestamp (ms) in each row.
series (required)readonly ChartSeries[]NoneUp to 4 lines, each with a fixed color slot.
timeZonestringthe viewer'sIANA time zone of the default time format, e.g. "UTC".
formatTime((time: Date) => string)"2:05:09 PM" (or "14:05:09") in localeFormats a timestamp as text.
limitnumber20Limits the rows shown, newest first.
captionstringNoneHidden caption that names the table for screen readers.

Keyboard

KeysAction
TabFocus the chart, then the Pause button.
←/→Read the previous / next sample; the view holds still while you read.
Home/EndOldest / newest sample in view.
Space/KPause or resume the view.
EscapeStop reading; the view catches up with the present.

Accessibility

  • Anything that moves on its own can be paused (WCAG 2.2.2): the Pause button is built in, and Space or K toggles it from the chart.
  • New samples are never announced on their own (that would be a flood); a sample read by keyboard is announced once, with every series' value.
  • The status pill says Live, Holding or Paused in words, and the latest values in the header double as the legend.
  • Reduced motion: no sliding, no pulse and no rolling numbers; the chart redraws in place once per sample.
  • Off-screen or in a background tab the chart rests (no frame loop, no redraw, no pulse); useStreamingData stops its timer in a background tab (and off-screen with `idle`), then fills in the gap so the chart glides to the present.
  • The table view lists the latest samples, newest first.

All exports on this page

  • StreamingChart — A live line chart: new samples glide in from the right as the time axis slides smoothly under them, like a heart-rate monitor.
  • StreamingTable — The latest samples, newest first: time and each series' value.
  • defaultStreamingChartLabels — The built-in English strings of StreamingChart; spread it into your own labels and change what you need.
  • useLiveData — Live (streaming) rows for any chart: appends next() every interval ms into a sliding window.
  • useStreamingData — A rolling buffer of samples: calls source(time, index) every rate ms and keeps the last capacity rows, { time, ...values }.

When to use the real-time chart

  • Use it as a live chart in React for an ops wall or a status page, such as requests per second and error rate over the last minute, where samples keep arriving and the line should glide along instead of redrawing.
  • It fits a monitoring panel fed by a WebSocket, because you can append your own rows to data and the chart animates them the same way as generated ones.
  • It also works as a fast feed with the axis anchored at zero, such as two samples a second with 40 seconds in view.
  • Skip it when data arrives rarely or the history is the point; LineChart handles a static range better, and Tracker fits status-by-day history.
  • Pair it with ChartCard for the title, useStreamingData to generate and buffer samples, and StreamingTable for the latest rows as text; the chart brings its own Live status and Pause button.

Frequently asked questions

48 charts pages in all: browse them on Charts.

By Lokendra Singh Rathore (GitHub, opens in a new tab). Published , updated .