Xzero UI
Pro library

Sparkline

Show a compact trend beside a value.

$ pnpm dlx shadcn@4.23.0 add @xzero-ui/sparkline
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/sparkline

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 { Sparkline } from "@/components/xzero/sparkline/sparkline";

export function Signups() {
  return (
    <Sparkline
      label="Signups"
      data={[12, 18, 15, 22, 30, 27, 34]}
      labels={["Mon", "Tue", "Wed", "Thu", "Fri", "Sat", "Sun"]}
      value="34"
      change="+26%"
      tone="success"
    />
  );
}

API reference

Sparkline

A small line chart with a headline value that can be scrubbed by pointer or keyboard.

PropTypeDefaultDescription
data (required)number[]–Points in order, oldest first.
label (required)string–What is measured. Names the chart.
valuestring–Headline value at rest. While scrubbing it shows the point under the cursor.
changestring–Aside text at rest, such as "+4.1%".
tone"accent" | "success" | "warning" | "danger""accent"Line and change color.
widthnumber160Drawing width in SVG units.
heightnumber52Drawing height in SVG units.
labelsstring[]–One label per point, such as a date, shown while scrubbing.
formatValue(value: number, index: number) => string–Formats a scrubbed point. Defaults to a grouped number.
areabooleantrueQuiet fill under the line.
interactivebooleantrueEnables pointer and keyboard scrubbing.

Keyboard interactions

KeysAction
ArrowLeft / ArrowRightMoves the cursor one point back or forward (ArrowDown and ArrowUp too).
PageDown / PageUpMoves about a sixth of the series.
Home / EndJumps to the first or last point.
EscapeStops scrubbing and returns to the latest value.

Accessibility

Motion

Responsive behavior

Performance

Notes for AI

Also in charts

Guidance for AI tools

Sparkline: Show a compact trend beside a value. 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