Skip to content
English

How it works

A self-contained widget card: header, counting hero, plot, axis and an optional legend. The plot is laid out in real pixels (a ResizeObserver measures it), with one column per label so the band, the point and the axis pill share a centre. Points and the tooltip are HTML placed with transform; the line is SVG drawn with pathLength and dashoffset. New data glides: points and the band transition, the path morphs through the CSS d property where supported (elsewhere it jumps), and the numbers count from what is on screen.

Use it for

  • A personal or team metric over a short run of periods, where the latest value is the story: weight, sleep, weekly sales.
  • A metric with a target you want to show as a line.
  • Comparing this period with a muted baseline on the same unit.

Look elsewhere when

  • Dense series (30+ points) or several tangled lines: use a full analytics chart with axes and gridlines.
  • Categories with no order, such as channels or regions: use bars.
  • A volume that adds up over time: the area chart reads better.

Usage

import { LineChart } from './LineChart.jsx'

const weeks = ['1', '2', '3', '4', '5', '6', '7', '8']

export function WeightCard() {
  return (
    <LineChart
      title="Weight"
      subtitle="last 8 weeks"
      onOpen={() => {}}
      caption={(week) => `Week ${week}`}
      unit="kg"
      delta={{ value: -0.6, label: 'vs last week', positive: 'down' }}
      categories={weeks}
      series={[{ name: 'Weight', data: [76.8, 76.1, 75.4, 75.6, 74.7, 74.2, 73.5, 72.9] }]}
      reference={{ value: 72, label: 'Goal' }}
      color={4}
    />
  )
}

Props

PropTypeDefaultWhat it does
categoriesstring[]—X-axis categories, usually dates or week numbers. One column and one point per label. `labels` is the older name of this prop and still works (deprecated: in blocks `labels` means text overrides).
series{ name: string, data: (number | null)[], color?: number | string, muted?: boolean }[]—Up to 4 lines. The first one that is not muted leads: it sets the hero, the band and the tooltip colour. muted draws a dotted grey comparison line (last year, a plan) with no points. color is 1–8 for --ds-chart-N or any CSS colour; null breaks the line.
title / subtitle / iconReactNode—Card header: a tinted icon tile, a 15px title and a quieter subtitle after it.
onOpen / action() => void / ReactNode—onOpen adds a chevron button at the end of the header. action replaces it with any node, such as a menu.
captionstring | (category: string, index: number) => string—Small line above the hero. A function receives the selected column, so the caption follows the selection.
valuenumber | string—Hero value. If omitted it is the lead series at the selected column. Numbers count from the old value to the new one.
unitstring—Unit after the hero and inside the tooltip, such as kg or %.
delta{ value: number, label?: string, positive?: 'up' | 'down', format?: (n) => string }—Change badge after the hero. positive: 'down' makes a fall green, for weight or cost.
reference{ value: number, label?: string }—A thin reference line with its value and label at the left, such as a goal. The y range always includes it.
selected / onSelectnumber / (index: number) => void—The column at rest, with the band, the big point and the ink axis pill. Defaults to the latest point; a click or Enter pins another one.
colornumber | string1Lead colour: 1–8 for --ds-chart-N with its soft partner, or a CSS colour. Further series take the next palette slots.
heightnumber132Plot height in px, not counting the axis labels under it.
smoothbooleanfalseMonotone curve that never overshoots into false peaks; false draws straight segments.
yMin / yMaxnumber—Y range. By default it hugs the data with a little headroom, so small changes stay visible.
formatValue(n: number) => string(n) => n.toLocaleString('en-US')Number format for the hero, tooltip, reference label, legend and screen-reader table.
showLegendbooleantrueWith two or more series, a legend whose values follow the selected or hovered column.
labelstring—Accessible name of the plot and caption of the hidden data table. Defaults to the title.
textobject—Replaces built-in text: open, tip(value, unit), plot(name, count), point(category, parts), noData, category. Named text because labels holds the categories.
replayKeystring | number—Change it to play the entrance again. Changing the categories also replays it; changing only values glides.
className / style / ...restHTMLAttributes—Passed to the card root, which fills its container width.

Accessibility

  • The plot is a focusable group named after the chart. Left and Right move between points, Home and End jump to the ends, Enter pins the column, Escape goes back to the pinned one.
  • Each move is announced through a polite live region; a visually hidden table holds every value.
  • The drawing is hidden from screen readers; the hero, delta and legend are real text.
  • The delta badge shows an arrow as well as colour.
  • Reduced motion shows the final chart at once and the numbers do not count.

Motion

Entrance waits until 30% of the card is visible. The line draws over 900ms on cubic-bezier(0.22, 1, 0.36, 1) while the hero counts; each point pops (420ms spring) exactly when the line reaches it; axis labels fade 30ms apart; the band rises at 520ms and the ink pill pops at 640ms. Hover moves the band and tooltip in 240ms; new data glides over 900ms.

Add it to your project

Copy the prompt into Codex or Claude Code. The agent reads the published source, shows you what it will write and adds the component next to your own.

LineChart.jsxline-chart.csstokens.cssREADME.md

Both files install together. The stylesheet reads the design tokens in tokens.css and carries fallbacks, so it also works alone.

Charts
Trilateration comes with Pro. Its preview shows once you unlock it.