Skip to content
weftGitHub

StreamChart

A live rolling window of a number, with a pause that shows the held data.

SourcePackage @weft-js/warp

Preview

tsx
import { state } from '@weft-js/core'import { interval } from '@weft-js/core/browser'import { StreamChart } from '@weft-js/warp'export function Live() {  const data = state(seed)  let t = 60  interval(1000, () => {    t++    data.value = [...data.value.slice(1), Math.round(52 + Math.sin(t / 5) * 14 + (t % 4))]  })  return <StreamChart title="Requests per second" description="storefront, updates every second" data={data.value} domain={[20, 90]} ticks={STREAM_TICKS} reference={SPIKE} unit="requests per second" span="−60 s" />}const seed = Array.from({ length: 60 }, (_, i) => Math.round(52 + Math.sin(i / 5) * 14 + (i % 4)))const SPIKE = { y: 75, label: 'Limit 75' }const STREAM_TICKS = [20, 40, 60, 80]

Installation

npm install @weft-js/warp

Usage

tsx
import { StreamChart } from '@weft-js/warp'

Accessibility

  • Every chart has a text alternative and a table view of its numbers, so nothing depends on seeing the marks. See Chart for its keyboard support.

API Reference

PropTypeDefaultDescription
titlestring—The heading.
level2 | 3 | 4 | 6 | 5—The title's heading level: one below the heading the chart sits under. Default 3, a chart in a page section.
descriptionunknown—One supporting line under the title.
toolbarunknown—Beside the view toggle: a layout switch, a range picker.
state"error" | "loading" | "empty"—Replaces the plot, in the same frame. With no data the frame shows empty on its own.
loadingstring—Shows that work is under way.
empty{ title: string; detail?: unknown; }—The title and detail shown in place of the plot when there is no data.
error{ title: string; detail?: unknown; }—A message that marks the field invalid and says why.
actionunknown—The next step under an empty or error state: a Retry button.
datanumber[]—The series to draw.
summarystring | ((c: { data: number[]; title: string; }) => string)—One sentence for screen readers and the page; generated from the data when absent.
domain[number, number]—The fixed y range, so the axis never jumps.
ticksnumber[]—The y labels.
referenceReference—A level to watch: { y, label }.
unitstring—What the number counts.
formatFmt—Turns a value into the text shown.
spanstring—The label on the left edge of the window.

RelatedLine chartSparkline