Xzero UI
Pro library

Slope chart

Before and after on two axes: lines draw in, rank moves sit beside each value, and switching datasets slides every line to its new slope.

$ pnpm dlx shadcn@4.23.0 add @xzero-ui/slope-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/slope-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 { SlopeChart } from "@/components/xzero/slope-chart/slope-chart";

const channels = [
  { key: "email", label: "Email", start: 3.1, end: 4.6 },
  { key: "search", label: "Organic search", start: 3.4, end: 3.6 },
  { key: "social", label: "Paid social", start: 1.9, end: 1.3 },
];

export function Channels() {
  return <SlopeChart data={channels} label="Conversion by channel" startLabel="Q1" endLabel="Q2" highlightKey="email" formatValue={value => `${value.toFixed(1)}%`} />;
}

API reference

SlopeChart

Before and after for several items on two shared axes. Lines draw in on first view, labels spread apart to avoid overlaps with a hairline back to their point, rank moves sit beside each end value, and switching datasets slides every line to its new slope.

PropTypeDefaultDescription
data (required)SlopeItem[]–Items: { key, label, start, end }. Keys keep lines stable across datasets.
label (required)string–What is measured. Names the chart, the summary, and the table.
startLabel (required)string–First column heading, such as "Q1".
endLabel (required)string–Second column heading, such as "Q2".
formatValue(value: number) => string–Formats values beside the points, in the tooltip, and in the table.
formatChange(change: number, item: SlopeItem) => string–Formats the change in the tooltip, such as "+1.5 pts".
heightnumber44px per itemPlot height in pixels.
highlightKeystring | nullnullThe item drawn in the first series hue, derived from the accent.
activeKeystring | null–Controlled item in focus. The others fade.
onActiveChange(key: string | null) => void–Called as the item in focus changes.
ranksbooleantrueRank movement beside each end value.
emptyLabelstring"No data"Message when there are no items.
refRef<HTMLElement>–Forwarded to the figure.
classNamestring–Extra class on the figure.

Keyboard interactions

KeysAction
TabFocuses the chart and reads the top item by end value.
ArrowDown / ArrowRightNext item in end order.
ArrowUp / ArrowLeftPrevious item.
Home / EndFirst or last item.
EscapeClears the reading.

Accessibility

Motion

Responsive behavior

Performance

Notes for AI

Also in charts

Guidance for AI tools

Slope chart: Before and after on two axes: lines draw in, rank moves sit beside each value, and switching datasets slides every line to its new slope. 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