Search documentation

Search pages, components, blocks, styles and colours.

Get started
Skip to content

Line Chart

PreviousNext

Change over time as lines for comparing series, with dashed targets and a gliding crosshair and tooltip.

Revenue against target
Acme Inc, 2026
Revenue against target
RevenueTarget
Jan$36K$36K
Feb$43K$39K
Mar$44K$41K
Apr$44K$44K
May$49K$46K
Jun$52K$49K
Jul$54K$51K
Aug$59K$54K
Sep$64K$56K
Oct$67K$59K
Nov$72K$61K
Dec$76K$64K

Give it rows of data, the field that places each row along the bottom (index) and a config that names the series to draw. Each series is a 2px line in the next colour of the chart palette; a dashed series reads as a target or a forecast. Point at the chart, drag a finger across it or tab to it and use the arrow keys: a crosshair finds the nearest row and a tooltip lists every series there. The legend hides a series when pressed and spotlights it when pointed at.

The lines draw in from the start edge the first time the chart is on screen, and morph to new values when the data changes. Line Chart is part of the Fabricator style. It shares its plot with Area Chart, which adds the wash under each line. It's drawn in SVG, so the same component ships for every base, and its layout comes from the same model as the React Native version.

Installation

bunx --bun fabricator-ui@latest add line-chart

Usage

import { type ChartConfig } from "@/components/ui/chart-kit"
import { LineChart } from "@/components/ui/line-chart"
const data = [
  { month: "Jan", actual: 36_400, target: 36_000 },
  { month: "Feb", actual: 43_000, target: 38_500 },
  { month: "Mar", actual: 43_900, target: 41_000 },
]
 
const config = {
  actual: { label: "Revenue" },
  target: { label: "Target", color: "muted-foreground", dashed: true },
} satisfies ChartConfig
 
<LineChart data={data} index="month" config={config} label="Revenue" />

Each key of config is a field of the rows. A missing or non-numeric value leaves a gap in the line. The chart fills its container's width and is 18rem tall until you give it a height with className.

Values print in full (1,234) until you pass formatValue. It also formats the hidden table, which renders on the server, so use a formatter that writes the same text in Node and in the browser: formatChartNumber(value, { compact: true }) from lib/chart-model gives 43.9K on both, where Intl's compact notation can differ between them.

Examples

Several series

Point at a series in the legend to spotlight it, so the others step back; press it to hide it. The others keep their colours, and the value axis rescales to what is left.

p95 latency by service, in milliseconds
APIWebWorkerCron
Mon182 ms240 ms96 ms41 ms
Tue176 ms251 ms104 ms44 ms
Wed214 ms233 ms131 ms39 ms
Thu198 ms262 ms122 ms52 ms
Fri241 ms288 ms158 ms47 ms
Sat132 ms174 ms88 ms45 ms
Sun121 ms162 ms79 ms43 ms

Curves and stacking

Line Chart takes the same curve and stack as Area Chart: smooth, linear or step, and none, stacked or expand.

Colours

Series take the chart palette in the order of config, and keep their colour when another is hidden. Give a series its own with color: a palette slot, an upstream chart token (chart-1 … chart-5), a role (primary, info, success, …), a CSS variable (var(--brand)) or any CSS colour.

TokenHueTokenHue
--chart-series-1blue--chart-series-5magenta
--chart-series-2orange--chart-series-6green
--chart-series-3aqua--chart-series-7violet
--chart-series-4amber--chart-series-8red

The palette ships with the foundations, chosen separately for light and dark. Every slot keeps 3:1 against the page and the card, and each colour stays apart from its neighbours for readers with red-green colour blindness. Slots never repeat: a ninth series is grey, so fold small series into an "Other" one before that.

Motion

  • Draw-in: the first time the chart scrolls into view, the lines sweep in from the start edge on the reveal role, once per mount.
  • Morph: when data, config, stack or the visible series change, each point moves to its new place on the move role. A series being shown grows from its baseline; one being hidden shrinks into it. Data with a different number of rows redraws instead.
  • Glide: the crosshair, dots and tooltip glide between rows on the glide role.

All three follow the motion speed of the region they sit in. Reduce Motion and the instant speed draw the chart at once and drop the glide; animate={false} does the same for one chart.

API Reference

LineChart

All other props go to the root <div>.

PropTypeDefault
dataTDatum[]required
configChartConfigrequired
indexkeyof TDatumrequired
labelstringrequired: the accessible name
curve"smooth" | "linear" | "step""smooth"
stack"none" | "stacked" | "expand""none"
formatValue(value: number, key: string) => string1,234
formatIndex(value: string, datum: TDatum) => stringthe field as text
legendbooleanon for two or more series
tooltipbooleantrue
animatebooleantrue
loadingbooleanfalse
emptyReactNode"No data"
onActiveChange(active: ChartActive<TDatum> | null) => void-

ChartConfig

FieldTypeDefault
labelstringrequired
colorChartColorthe next palette slot
dashedbooleanfalse

Data attributes

AttributeElementPresent when
data-slot="line-chart"rootalways
data-loadingrootloading is true
data-slot="chart-plot"the plotalways
data-slot="chart-series"a seriesalways; data-dimmed while another is spotlit
data-slot="chart-legend"the legendthe legend shows
data-slot="chart-tooltip"the tooltipa row is inspected

Accessibility

  • The chart's plot is a slider named after label ("Monthly revenue: inspect values"). Tab to it, then Left and Right step through the rows, Home and End jump to the first and last, and Escape lets go. Its value text reads the tooltip: the row and every series' value.
  • Every value is also in a table hidden from sight, so a screen reader can read the data without inspecting it.
  • With two or more series the legend always shows, so no series is told apart by colour alone. Its items are toggle buttons with aria-pressed.
  • Text never takes a series colour: values and labels stay in the text colours, beside a coloured key.
  • loading sets aria-busy on the root and dims the last drawing until new data arrives.