Xzero UI
Pro library

Line chart

A multi-series line chart with a gliding crosshair, legend toggles, and paths that morph between ranges.

$ pnpm dlx shadcn@4.23.0 add @xzero-ui/line-chart
Live · keyboard ready

When to use

When not to use

Installation

Register both Xzero UI namespaces in your project's components.json:

{
  "registries": {
    "@xzero-ui": "https://mcp.xzero.co.uk/r/{name}.json",
    "@xzero-ui-pro": "https://mcp.xzero.co.uk/r/pro/{name}.json"
  }
}
npx shadcn@4.23.0 add @xzero-ui/line-chart

Install xzero-foundation once, and import @/components/xzero/foundation.css in your app root. No Xzero token is used by this snapshot. For sample portraits, photos, fonts, or logos, download https://mcp.xzero.co.uk/install-assets.mjs and run node xzero-install-assets.mjs <receiving-project>.

Usage

import { LineChart } from "@/components/xzero/line-chart/line-chart";

const data = [
  { key: "2026-09-01", label: "Tue, Sep 1", axisLabel: "Sep 1", values: { signups: 120, previous: 98 } },
  { key: "2026-09-02", label: "Wed, Sep 2", values: { signups: 142, previous: 104 } },
  { key: "2026-09-03", label: "Thu, Sep 3", axisLabel: "Sep 3", values: { signups: 131, previous: 110 } },
];

export function SignupsChart() {
  return (
    <LineChart
      label="Signups"
      data={data}
      series={[
        { key: "signups", label: "This period" },
        { key: "previous", label: "Previous period", dashed: true },
      ]}
    />
  );
}

Examples

Headline readout driven by the crosshair

const [active, setActive] = useState<LineChartDatum | null>(null);

<p>{(active ?? data[data.length - 1]).values.signups}</p>
<LineChart label="Signups" data={data} series={series} onActiveChange={(_, datum) => setActive(datum)} />

API reference

LineChart

An SVG line chart with a scrubbable crosshair, series toggles, morphing data changes, and a screen reader data table.

PropTypeDefaultDescription
data (required)LineChartDatum[]–Points: { key, label, axisLabel?, values }. values maps series keys to numbers; a missing value counts as zero.
series (required)LineChartSeries[]–Lines: { key, label, color?, dashed?, area? }. area defaults to true for the first series.
label (required)string–What is measured, such as "Signups". Names the chart for assistive technology.
unitstring""Unit after each value in the tooltip and table, such as "ms".
heightnumber220Plot height in pixels. The width follows the container.
formatValue(value: number, series: LineChartSeries) => string–Formats values in the tooltip and data table. Defaults to grouped numbers with one decimal.
formatTick(value: number) => stringcompact formatFormats the value axis, such as 1.2K.
hiddenSeriesstring[]–Controlled hidden series keys.
defaultHiddenSeriesstring[]–Hidden series keys on first render when uncontrolled.
onHiddenSeriesChange(hidden: string[]) => void–Called when a legend toggle changes the hidden keys.
onActiveChange(index: number | null, datum: LineChartDatum | null) => void–Called as the crosshair moves, and with null when it leaves. Use it to drive a headline readout.
loadingbooleanfalseDims the current lines while the next range loads, or shows a skeleton when there is no data.
emptyLabelstring"No data for this range"Shown when there are no points.
legendboolean–Series toggles above the plot. Shown by default when there is more than one series.
categoryLabelstring"Date"Header of the first column in the screen reader table, and part of the plot's slider label.
curve"smooth" | "linear""smooth"Monotone curves that never swing past the data, or straight segments.
refRef<HTMLElement>–The figure element.
classNamestring–Class on the figure.

Keyboard interactions

KeysAction
ArrowLeft / ArrowDownMoves the crosshair to the previous point.
ArrowRight / ArrowUpMoves to the next point; from rest it starts on the latest point.
PageUp / PageDownJumps about a sixth of the range.
Home / EndJumps to the first or last point.
EscapeLets go of the crosshair.

Accessibility

Motion

Responsive behavior

Performance

Notes for AI

Also in charts

Guidance for AI tools

Line chart: A multi-series line chart with a gliding crosshair, legend toggles, and paths that morph between ranges. Follow the declared prop types and do not invent props. Keep keyboard access, reduced motion support, and both light and dark themes intact when adapting it.

Full library index: https://ui.xzero.co.uk/llms.txt

Browse all components