This page as markdown: /line-chart.md · Index for agents: /llms.txt · Everything in one file: /llms-full.txt

LineChart

Status: beta

Lines over a sequence — for comparing how measures move. Smooth, linear or step curves, optional dots (coloured by series or by category) and value labels. Lines draw on as the chart scrolls into view.

Keywords: chart, line, trend, time series, graph, compare, analytics, dashboard

Usage

Use LineChart to compare how two or more measures change over the same sequence, or to show one trend precisely (with dots and labels). Unlike AreaChart, its value axis is fitted to the data rather than forced to zero, so small movements stay visible — say so if the axis is shown.

Best practices

Props

Name Type Default Description
data Record<string, unknown>[] — The rows, in order along the category axis.
index string — The datum field naming each row's category (a month, a day, a channel).
series { key: string; label: string; tone?: ChartTone; color?: string; icon?: string }[] — The measures to plot: the datum field, its name in the legend/tooltip/table, and its colour (a tone by role, or any CSS colour). Omitted, series take the chart palette in order: --chart-1 … --chart-8, validated for colour-blind separation in light and dark; a theme may override the set.
label string — What the chart shows. Its accessible name and the caption of the data table assistive tech reads.
className string "h-60" Sizes the chart (plot + legend). Set a height: h-72, aspect-video h-auto.
valueFormatter (value: number) => string — Format values everywhere (axis, labels, tooltip, table) — units like "$12,480". Default: compact on the axis, full elsewhere.
indexFormatter (value: string) => string — Shorten category labels on the axis ("January" → "Jan"); the tooltip keeps the full value.
locale string runtime locale BCP 47 locale for default number and date formatting.
tooltip boolean | { indicator?: "dot" | "line" | "dashed" | "none"; hideLabel?: boolean; labelFormatter?: (label, datum) => ReactNode; showTotal?: boolean; cursor?: "line" | "dashed" | "none"; order?: "series" | "reverse" } true Show a tooltip on hover and keyboard focus, or configure it: the row marker, hiding the heading, rewriting it, adding a Total row, the cursor, the row order.
legend boolean true when there is more than one series Show the legend under the chart.
grid boolean true (false for horizontal bars) Hairline gridlines along the value axis.
xAxis boolean true for columns; false for horizontal bars The horizontal axis.
yAxis boolean false for columns; true for horizontal bars The vertical axis.
yAxisSide "left" | "right" "left" Which edge the value axis sits on, on a vertical chart.
yAxisWidth number — The vertical axis's label width, in px. Left unset it follows the longest label, so the plot slides sideways when new data changes the labels; set it where a chart swaps data in place, such as tabs.
categoryTicks number — At most this many category labels. They already thin to fit, from the latest back; this asks for fewer.
domain "auto" | [number, number] — The value axis's range. A line chart already fits its data; a [min, max] pair fixes the range, and values past it stop at the plot's edge.
referenceLines ChartReferenceLine[] — Mark positions on the plot, each { category } or { value }, with an optional label and tone: a Today line, a target.
axisFormatter (value: number) => string — Format values on the axis alone, when it needs less than valueFormatter prints: $50K beside $41,746.08.
lineWidth number 2 The line's weight, in px.
motion "full" | "subtle" | "off" "full" How much motion this component uses: full (default) inherits the app's policy, subtle keeps feedback and drops the flourish, off stills it. It can only turn motion down — it never overrides a reader's reduce-motion setting. The arrival (lines drawing on) and the data-change morph are the flourish; the gliding cursor, dots and tooltip are the feedback subtle keeps.
animate boolean true Play the arrival once the chart scrolls into view. Reduced motion shows the finished chart. animate={false} is motion="subtle".
activeIndex number | null — The highlighted row (controlled); null for none.
defaultActiveIndex number | null — The row highlighted at first — a tooltip already open before anyone hovers.
onActiveIndexChange (index: number | null) => void — Called as the pointer or keyboard moves between rows.
curve "smooth" | "linear" | "step" "smooth" How the line runs between points. smooth is monotone: it never overshoots a value the data does not contain.
dots boolean false Mark every data point with a dot.
colorBy "series" | "index" "series" Colour the dots by series, or each by its category.
labels boolean false Print each point's value above it.

Tokens used

tone-1, tone-2, tone-3, tone-info, tone-warning, primary, muted-foreground, border, popover, popover-foreground, foreground, background, tone-warning-mark, tone-info-mark, tone-1-mark, tone-2-mark, tone-3-mark

Motion

Accessibility

Related

Examples

Compare two series

import { LineChart } from "@sableui/react"

<LineChart
	label="Desktop and mobile visitors"
	data={visitors}
	index="month"
	series={[
		{ key: "desktop", label: "Desktop", tone: "primary" },
		{ key: "mobile", label: "Mobile", tone: "info" },
	]}
	indexFormatter={(m) => m.slice(0, 3)}
/>

Dots and labels

import { LineChart } from "@sableui/react"

<LineChart
	label="Desktop visitors"
	data={visitors}
	index="month"
	series={[{ key: "desktop", label: "Desktop" }]}
	curve="linear"
	dots
	labels
	grid={false}
/>