<!-- generated by scripts/gen-docs.mjs from docs/system/chart.md. Edit the source and rerun. -->
# Chart

## Description
The frame every chart draws in: it holds the chart's box at a fixed height in every state, lets a person read any point by pointer, touch or keyboard, and gives a screen reader the same numbers as a sentence and a table.

`import { Chart, ChartLegend, ChartChange, ChartReferenceLine, ChartReferenceBand, type ChartConfig } from "@/components/cobalt/ui/chart"`, source `registry/cobalt/ui/chart.tsx`, status `ready-with-gaps`.
Foundation: `hand-rolled`. Traps checked: `trap/loading-layout-shift`, `trap/color-only-status`, `trap/live-region-double`, `trap/reduced-motion-ignored`, `trap/motion-transition-all`, `trap/motion-layout-property`, `trap/numbers-shift`, `trap/tooltip-essential`, `trap/tooltip-interactive`, `trap/touch-hover-flash`, `trap/hover-unguarded` (n/a: no CSS hover reveals anything; the overlay follows the hover store), `trap/demo-on-timers` (n/a: every example holds fixed data), `trap/illustration-announced` (n/a: the marks are `aria-hidden` and the table carries the data), `trap/loop-offscreen` (n/a: nothing loops).

### Foundation
Not applicable: hand-rolled.

| Given by the foundation | Added by the team |
|---|---|
| `d3-scale`, `d3-shape` and `d3-array` for the maths only: linear and band scales, nice ticks, line, area and `bisectCenter` | The whole frame: a box of fixed height (`h-32`, `h-48`, `h-72`) measured with one `ResizeObserver`; marks drawn once per data and size; a hover store read through `useSyncExternalStore`, so only the overlay (crosshair, markers, tooltip, live line) redraws on hover; pointer moves batched to one per frame and read from the event's own offset; the tooltip in the plain Tooltip's own surface (`tooltipSurface`) with no arrow, since the crosshair, the lit bar, the ringed dot or the outlined cell already points at the data, with `px-2.5 py-2` of its own because it holds a title and rows of figures, rendered in the portal and fixed to the window so no box or card clips it, placed before paint 6px (`TOOLTIP_OFFSET`) above the plot on lines, areas, columns, bins and steps, so it never covers a mark, above the hovered dot or cell on a scatter or a heatmap, and beside the bar's end on bars that run from the left, centred on the mark and kept over the plot where it fits so it never covers the value axis, below only when the window has no room above, kept 8px inside the window, and following the mark as the page scrolls; axis labels measured in the box's own font with tabular figures; under bars of named groups, and under up to six dated bars, every bar's label, on one line where the labels fit 8px apart and a label too wide for its band broken onto two lines at a space, the plot giving up the line it needs (`bandLabels`), else shortened with an ellipsis or thinned; from a hidden span, since a canvas cannot set tabular figures and Manrope's are 3.6px wider over "−$1,000M"; a pending chart with marks on screen keeps them, dimmed to 55% after `useSlowWait` with its hover off, as a list does while it reloads; new data fades the marks in with the system's crossfade, and data arriving after the Skeleton with `--t-fade`, never on the first paint and never under reduced motion; one tab stop with arrows, Home, End, Page Up, Page Down and Escape; the empty, pending (Skeleton after `useSlowWait`) and failure (Empty with Retry) states; a visually hidden summary and table; a point with no value said as "Unknown", or the reason a row gives through `missing()` from `registry/cobalt/lib/missing.ts`, in the muted ink through MissingValue, in the tooltip and the table, never "None", which reads as zero; `ChartLegend` and `ChartChange`; a canvas layer (`ChartCanvas`) for marks past 5,000; `layers`, `ChartReferenceLine` and `ChartReferenceBand` for marks of your own;
 a keyed `config` with `--color-<key>` on the root; lists that grow with the data are read with `maxOf` and `minOf` from `chart-math.ts`, never spread onto the call stack, which throws past about 150,000 values |

## Examples
The parts every chart shares: a legend of rounded squares and changes written with a sign and an arrow.

Real uses, 0 call sites (`rg -n "<Chart\b" app docs/system/examples --glob '!docs/system/examples/chart/*'`): every chart type renders the frame from inside `registry/cobalt/ui`, which the count leaves out.

Uses inside the registry: `XYChart` (`LineChart`, `AreaChart`, `BarChart`), `Histogram`, `ScatterChart`, `Heatmap` and `WaterfallChart` each render it; `ChartCard` renders `ChartChange`.

### Example files
| File | Covers | Caption |
|---|---|---|
| `docs/system/examples/chart/default.tsx` | default | The parts every chart shares: a legend of rounded squares and changes written with a sign and an arrow |
| `docs/system/examples/chart/height-sm.tsx` | height=sm | The short height, 128px, for a chart in a card of a dashboard grid |
| Not applicable: md is the default height, the chart in in-card.tsx | height=md | The middle height |
| `docs/system/examples/chart/height-lg.tsx` | height=lg | The tall height, 288px, for the one chart a page is about |
| `docs/system/examples/chart/state-pending.tsx` | state:pending | While the first data loads, a block holds the chart's exact size, after a short wait so a quick answer never flashes |
| `docs/system/examples/chart/state-failure.tsx` | state:failure | When the data fails to load, the box says so and offers Retry, at the same size |
| `docs/system/examples/chart/state-empty.tsx` | state:empty | With nothing to draw, a sentence that says why sits where the chart would be, at the same size |
| `docs/system/examples/chart/in-card.tsx` | composition:Card | A chart in a card: the card's title names it for the eye, the chart's label names it for a screen reader |

Example: The parts every chart shares: a legend of rounded squares and changes written with a sign and an arrow (`docs/system/examples/chart/default.tsx`)

```tsx
import { ChartChange, ChartLegend } from "@/components/cobalt/ui/chart";

const items = [
  { key: "equity", label: "Equity", color: "var(--chart-1)" },
  { key: "credit", label: "Credit", color: "var(--chart-2)" },
  { key: "real", label: "Real assets", color: "var(--chart-3)" },
  { key: "before", label: "A year before", color: "var(--chart-previous)", dashed: true },
];

export default function Example() {
  return (
    <div className="flex flex-col gap-4">
      <ChartLegend items={items} />
      <div className="flex flex-wrap gap-2">
        <ChartChange value={6.1} />
        <ChartChange value={-2.4} />
        <ChartChange value={-3.2} positive="down" />
        <ChartChange value={0} />
      </div>
    </div>
  );
}
```

Example: A chart in a card: the card's title names it for the eye, the chart's label names it for a screen reader (`docs/system/examples/chart/in-card.tsx`)

```tsx
import { type ChartHeight } from "@/components/cobalt/ui/chart";
import { Card, CardContent, CardDescription, CardHeader, CardTitle } from "@/components/cobalt/ui/card";
import { LineChart } from "@/components/cobalt/ui/line-chart";

// Form ADV amendments filed each month, October 2025 to September 2026.
const amendments = [184, 203, 177, 221, 248, 196, 230, 262, 241, 219, 257, 274];
const months = amendments.map((count, i) => ({
  month: new Date(Date.UTC(2025, 9 + i, 1)).toISOString().slice(0, 10),
  amendments: count,
}));
const series = [{ key: "amendments", label: "Amendments", value: "amendments" as const }];
const height: ChartHeight = "md";

export default function Example() {
  return (
    <Card className="w-full max-w-xl">
      <CardHeader>
        <CardTitle render={<h2 />}>Form ADV amendments</CardTitle>
        <CardDescription>Filed each month, October 2025 to September 2026.</CardDescription>
      </CardHeader>
      <CardContent>
        <LineChart label="Form ADV amendments per month" height={height} data={months} x="month" series={series} />
      </CardContent>
    </Card>
  );
}
```

## Variants

### height
- `sm`: 128px, a chart in a card of a dashboard grid, beside a headline figure. Used at 0 call sites.
- `md`: 192px, the default, a chart that is one part of a page. Used at 0 call sites.
- `lg`: 288px, the chart a page is about, or 12 series. Used at 0 call sites.

Example: The short height, 128px, for a chart in a card of a dashboard grid (`docs/system/examples/chart/height-sm.tsx`)

```tsx
import { type ChartHeight } from "@/components/cobalt/ui/chart";
import { LineChart } from "@/components/cobalt/ui/line-chart";

// Form ADV amendments filed each month, October 2025 to September 2026.
const amendments = [184, 203, 177, 221, 248, 196, 230, 262, 241, 219, 257, 274];
const months = amendments.map((count, i) => ({
  month: new Date(Date.UTC(2025, 9 + i, 1)).toISOString().slice(0, 10),
  amendments: count,
}));
const series = [{ key: "amendments", label: "Amendments", value: "amendments" as const }];
const height: ChartHeight = "sm";

export default function Example() {
  return <LineChart label="Amendments per month" height={height} data={months} x="month" series={series} />;
}
```

Example: The tall height, 288px, for the one chart a page is about (`docs/system/examples/chart/height-lg.tsx`)

```tsx
import { type ChartHeight } from "@/components/cobalt/ui/chart";
import { LineChart } from "@/components/cobalt/ui/line-chart";

// Form ADV amendments filed each month, October 2025 to September 2026.
const amendments = [184, 203, 177, 221, 248, 196, 230, 262, 241, 219, 257, 274];
const months = amendments.map((count, i) => ({
  month: new Date(Date.UTC(2025, 9 + i, 1)).toISOString().slice(0, 10),
  amendments: count,
}));
const series = [{ key: "amendments", label: "Amendments", value: "amendments" as const }];
const height: ChartHeight = "lg";

export default function Example() {
  return <LineChart label="Amendments per month" height={height} data={months} x="month" series={series} />;
}
```

## States
| State | Trigger | What the user can do | Shown by, besides color | Checked by |
|---|---|---|---|---|
| idle | data with at least one value that is not zero | read the marks, hover, tab in | the marks, the axes, the legend | screenshot |
| hover | the pointer over the box, snapped to the nearest point, bar or cell | read the tooltip, move along | the tooltip 6px above the plot on lines, areas, columns, bins and steps, so it covers no mark, 6px above a dot or a cell, and 6px beside the end of a bar that runs from the left; on lines and dots a 1px crosshair and a marker per point, the dot's own radius with a 2px ring of the card around it; on a heatmap a 1.5px outline whose inner edge lies on the cell and whose corners are the cell's plus 0.75px, so the two are concentric; on bars the others dim to 40% | screenshot |
| focus | Tab reaches the box | step with the arrow keys | the system focus outline on the box, the last point shown, the live line read aloud | by hand |
| pending | `status="pending"` with nothing drawn yet | wait | `aria-busy`; nothing for 250ms, then a Skeleton block at the box's size | test |
| refreshing | `status="pending"` with marks on screen | read the old marks | `aria-busy`; after 250ms the marks dim to 55% and the hover stops; the new marks fade in when they arrive | by hand |
| empty | no value, or every value zero, and not pending | read why | the sentence "Nothing to show for this period." centred in the box | test |
| failure | `status="failure"` | press Retry | the title "Could not load the chart" announced once as an alert, and Retry when `onRetry` is passed | test |

Example: While the first data loads, a block holds the chart's exact size, after a short wait so a quick answer never flashes (`docs/system/examples/chart/state-pending.tsx`)

```tsx
import { type ChartLabels } from "@/components/cobalt/ui/chart";
import { LineChart } from "@/components/cobalt/ui/line-chart";

const months: { month: string; amendments: number }[] = [];
const series = [{ key: "amendments", label: "Amendments", value: "amendments" as const }];
// Read to a screen reader while the block shows.
const labels: Partial<ChartLabels> = { loading: "Loading amendments" };

export default function Example() {
  return (
    <LineChart label="Amendments per month" labels={labels} status="pending" data={months} x="month" series={series} />
  );
}
```

Example: When the data fails to load, the box says so and offers Retry, at the same size (`docs/system/examples/chart/state-failure.tsx`)

```tsx
import { type ChartLabels } from "@/components/cobalt/ui/chart";
import { LineChart } from "@/components/cobalt/ui/line-chart";

const months: { month: string; amendments: number }[] = [];
const series = [{ key: "amendments", label: "Amendments", value: "amendments" as const }];
const labels: Partial<ChartLabels> = { failure: "Could not load the amendments" };

export default function Example() {
  return (
    <LineChart
      label="Amendments per month"
      labels={labels}
      status="failure"
      onRetry={() => {}}
      data={months}
      x="month"
      series={series}
    />
  );
}
```

Example: With nothing to draw, a sentence that says why sits where the chart would be, at the same size (`docs/system/examples/chart/state-empty.tsx`)

```tsx
import { type ChartLabels } from "@/components/cobalt/ui/chart";
import { LineChart } from "@/components/cobalt/ui/line-chart";

// The adviser has filed no amendments since registering in September.
const months: { month: string; amendments: number }[] = [];
const series = [{ key: "amendments", label: "Amendments", value: "amendments" as const }];
const labels: Partial<ChartLabels> = { empty: "No amendments filed since registration." };

export default function Example() {
  return <LineChart label="Amendments per month" labels={labels} data={months} x="month" series={series} />;
}
```

### State precedence
- Failure and pending: failure wins. The box shows the failure and its Retry.
- Pending and empty: pending wins. The box stays blank, then shows the Skeleton after the slow wait; the empty sentence never flashes.
- Pending and idle: both show. The old marks stay, dimmed to 55% once the slow wait passes, until the new data arrives; the Skeleton is only for a box with nothing drawn yet.
- Hover and focus: the last one wins. The pointer and the keys move the same marker, so one point shows at a time.

### Motion
| Trigger | Kind | Preset | Properties | Reduced motion |
|---|---|---|---|---|
| the crosshair, markers and tooltip appear or leave | announce | `popup-motion` at `--t-press` 140ms on `--curve`, leaving at 70% | opacity | the same fade, which the base layer keeps |
| the hovered point changes | input | none: the crosshair, the markers and the tooltip snap together with no transition, so the tooltip never trails the crosshair and never slides text that has already changed; the tooltip fades only as it appears and leaves | transform | the same snap |
| a bar dims beside the hovered one, a legend item brings its series forward | announce | `duration-press` on `--curve` | opacity | the same fade |
| the Skeleton appears | announce | the Skeleton's own wait and fade, `--t-fade` | opacity | no pulse |
| the data changes while the chart is on screen, such as a range switch | announce | the system's crossfade: the old marks go at once and the new ones fade in over `--t-crossfade` 320ms on `--curve-sheet`; a resize or a hidden series redraws at once | opacity | none: the new marks are drawn at once |
| the first data arrives after the Skeleton | announce | `--t-fade` 150ms on `--curve` | opacity | none |
| a refresh passes the slow wait | announce | `duration-fade` on `--curve` | opacity, to 55% | the same fade |

## Props

<!-- Props generated from registry/cobalt/ui/chart.tsx with TypeScript by scripts/props-table.mjs -->
### Chart

| Prop | Type | Default | Purpose |
|---|---|---|---|
| `draw` | `(size: ChartSize) => ChartDrawing` |  |  |
| `empty` | `boolean` |  | No data to draw: the box shows the empty sentence. |
| `label` | `string` |  | What the chart shows, read as its name: "Fund assets". |
| `summary` | `string` |  | The sentence a screen reader hears before the table. |
| `table` | `ChartTable` |  |  |
| `active?` | `number` |  | The hovered index, for a headline that follows the pointer or two linked charts. |
| `boxClassName?` | `string` |  | The box's own height, in place of `height`, for a chart that is one line: CompositionBar. |
| `className?` | `string` |  |  |
| `focusSeries?` | `string` |  | A series to bring forward: the others dim. |
| `height?` | `ChartHeight` |  | `sm` 128px; `md` 192px; `lg` 288px. |
| `labels?` | `Partial<ChartLabels>` |  |  |
| `layers?` | `((scope: ChartScope) => ReactNode)` |  | Your own SVG over the marks, drawn with the chart's scales. |
| `legend?` | `ReactNode` |  |  |
| `onActiveChange?` | `((index: number) => void)` |  |  |
| `onRetry?` | `(() => void)` |  | Shown as Retry in the failure state. |
| `status?` | `Status` |  |  |
| `style?` | `CSSProperties` |  | Set on the chart's root: the `--color-<key>` of a keyed `config`. |
| `tooltip?` | `boolean` |  | Show the tooltip on hover and focus. |
| `version?` | `string \| number` |  | What the data says, as a value that changes only when the data does: a new one fades the marks in, so a range switch reads as new data. |

### ChartCanvas

| Prop | Type | Default | Purpose |
|---|---|---|---|
| `colors` | `readonly string[]` |  |  |
| `height` | `number` |  | `sm` 128px; `md` 192px; `lg` 288px. |
| `paint` | `(context: CanvasRenderingContext2D, resolved: string[]) => void` |  |  |
| `width` | `number` |  |  |

### ChartLegend

| Prop | Type | Default | Purpose |
|---|---|---|---|
| `items` | `readonly ChartLegendItem[]` |  |  |
| `className?` | `string` |  |  |
| `onFocusChange?` | `((key: string) => void)` |  |  |
| `onToggle?` | `((key: string) => void)` |  |  |

### ChartChange

| Prop | Type | Default | Purpose |
|---|---|---|---|
| `value` | `number` |  | The change in percent, signed: 2.4 is a rise. |
| `className?` | `string` |  |  |
| `locale?` | `string` |  |  |
| `positive?` | `"up" \| "down"` | `"up"` |  |

### ChartReferenceBand

| Prop | Type | Default | Purpose |
|---|---|---|---|
| `scope` | `ChartScope` |  |  |
| `label?` | `string` |  |  |
| `x?` | `readonly [string \| number \| Date, string \| number \| Date]` |  |  |
| `y?` | `readonly [number, number]` |  |  |

### ChartReferenceLine

| Prop | Type | Default | Purpose |
|---|---|---|---|
| `scope` | `ChartScope` |  |  |
| `label?` | `string` |  |  |
| `x?` | `string \| number \| Date` |  |  |
| `y?` | `number` |  |  |

### ChartSwatch

| Prop | Type | Default | Purpose |
|---|---|---|---|
| `color` | `string` |  |  |
| `dashed?` | `boolean` |  |  |
| `faded?` | `boolean` |  |  |

### ChartGrid

| Prop | Type | Default | Purpose |
|---|---|---|---|
| `plot` | `ChartPlot` |  |  |
| `ticks` | `readonly { y: number; label: string; }[]` |  |  |
| `zero?` | `number` |  |  |

### ChartXAxis

| Prop | Type | Default | Purpose |
|---|---|---|---|
| `measure` | `(text: string) => number` |  |  |
| `ticks` | `readonly { x: number; label: AxisLabel; }[]` |  |  |
| `width` | `number` |  |  |
| `y` | `number` |  |  |
| `gap?` | `number` | `12` |  |
| `lines?` | `1 \| 2` | `1` |  |

### XYChart

| Prop | Type | Default | Purpose |
|---|---|---|---|
| `data` | `readonly T[]` |  |  |
| `label` | `string` |  |  |
| `mode` | `XYMode` |  |  |
| `series` | `readonly ChartSeries<T>[]` |  |  |
| `x` | `Accessor<T, string \| number \| Date>` |  | The position along the bottom: a date (Date or ISO string), a number or a name. |
| `active?` | `number` |  |  |
| `className?` | `string` |  |  |
| `config?` | `ChartConfig` |  | Names and colours by series key, as shadcn's `ChartConfig`. |
| `domain?` | `readonly [number, number]` |  | A fixed value range, in place of the one read from the data. |
| `format?` | `ValueFormat` | `"number"` | How values read on the axis and in the tooltip. |
| `height?` | `ChartHeight` |  | `sm` 128px; `md` 192px; `lg` 288px. |
| `labels?` | `Partial<ChartLabels>` |  |  |
| `layers?` | `((scope: ChartScope) => ReactNode)` |  | Your own SVG, drawn over the marks with the chart's scales: a reference line, a band, a note. |
| `legend?` | `"auto" \| "none"` | `"auto"` | "auto" shows it for two series or more, or a comparison; "none" hides it. |
| `locale?` | `string` |  |  |
| `onActiveChange?` | `((index: number) => void)` |  |  |
| `onRetry?` | `(() => void)` |  |  |
| `status?` | `Status` |  |  |
| `summary?` | `string` |  | Your own sentence for screen readers; one is written from the data otherwise. |
| `tooltip?` | `boolean` |  |  |
| `xFormat?` | `((value: string \| number \| Date) => string)` |  | How an x value reads in the tooltip and table, in place of the default date or name. |

`draw` returns the marks and the geometry for a size; a chart type supplies it, and a page uses a chart type instead. `empty`, `summary` and `table` come from the chart type's data. `labels` replaces any of the words. `tooltip={false}` keeps the crosshair and markers and drops the tooltip. `active` and `onActiveChange` share the hovered point, so a headline can follow it, and they speak in the row's index in `data` on every chart with one mark per row (line, area, bar, scatter, waterfall), whatever order it draws in; a histogram speaks in bins and a heatmap in cells across the whole grid, since they gather rows. `layers` takes a function of the chart's `ChartScope`, its `x` and `y` scales in the box's pixels, the plot box, the size and a bar's band, and draws your SVG over the marks: a reference line, a band, a note or a mark of your own, with no fork. It re-renders with the page, apart from the marks, so a layer that reads state never redraws the data. `ChartReferenceLine` is the common one: `y` draws a dashed line across at a value, `x` up the plot at a date or a category, with an optional `label`. `ChartReferenceBand` shades a range: `y` between two values across the plot, `x` between two dates, numbers or categories up it, a category taking its whole bar, in a 5% tint of the text colour with an optional `label` inside its top-left corner. A chart type passes the frame a `version`, which changes only when its data says something else, so new data fades in and a resize does not; `boxClassName` gives a one-line chart such as CompositionBar its own box height.
 Line, area and bar charts take `config`, names and colours by series key in the shape of shadcn's `ChartConfig`; each series' colour, from `config` or else its place in `--chart-1` to `--chart-6`, is set on the chart's root as `--color-<key>`. Props written inline, such as `series`, `config`, `labels`, an accessor or a format function, are held steady across renders, so a page that re-renders on every hovered point redraws no marks; `data` is compared by identity. `focusSeries` dims every series but one. `height` sets the box. `ChartLegend` takes `items` and an optional `onToggle` and `onFocusChange`. `ChartChange` takes a signed percentage `value`, `positive` and `locale`.

## Usage

### When to use
- A number changes over time or across groups and the shape of that change is the point, such as fund assets each month.
- A custom chart type needs the same hover, keyboard, states and table as the rest: draw it inside the frame.

### When not to use
- One figure and its change, with no history worth a picture. Use Stat instead.
- A ranked list of names whose values a person reads one by one. Use BarList instead.
- Records a person sorts, filters and opens. Use DataTable instead.

### Rules
- `rule/chart-one-unit-per-axis`: When an axis labels its ticks, use `tickFormatter` from `chart-math.ts`, which gives every tick one unit, the column's unit from `unitFor` moved up while the top tick reaches 1,000 of it, and one precision (0, 0.5B, 1.0B, 1.5B, never 1,500M or 1B beside 1.5B), and `labelFormatter` for the figures printed at a series' marks, whose figures in one unit share their decimals (33.0B beside 29.4B), instead of formatting each figure on its own, because 800M beside 1.2B on one axis reads as a smaller number above a larger one, and 33B beside 29.4B leaves the column ragged. Evidence: principle heuristic: consistency and standards, one column of figures shares one unit; single use registry/cobalt/lib/chart-math.ts:125. Check: test `chart-math.test.ts` expects "$1,200B" beside "$400B", "$1.0B" and "$1.5B" where the column's unit would write "$1,000M" and "$1,500M", and "33.0B" beside "29.4B" from `labelFormatter`.
  - Don't: `<LineChart format={(v) => compactMoney(v)} ... />`
  - Do: `<LineChart format="money" ... />`
- `rule/chart-height-not-ratio`: When a chart sits on a page, give it one of the three `height` steps instead of an aspect ratio or a height read from the data, because the box must have its final height before it is measured, or the page moves when the marks arrive. Evidence: person D37; measured layout shift 0 while hovering 160 points on every chart type, .design-system/evidence/charts/hover-cost.jsonl. Check: test `chart.test.tsx` finds `h-72` on the box before measuring.
  - Don't: `<div className="aspect-video"><LineChart ... /></div>`
  - Do: `<LineChart height="lg" ... />`
- `rule/chart-label-names-the-data`: When a chart is placed, give `label` the name of what it measures, such as "Gross assets", even when a heading above says it, because the label is the chart's accessible name, the table's caption and the first words of its summary. Evidence: principle wcag: 1.1.1 Non-text content; principle wcag: 4.1.2 Name, role, value. Check: test `chart.test.tsx` expects the caption and the summary.
  - Don't: `<LineChart label="Chart" ... />`
  - Do: `<LineChart label="Gross assets" ... />`
- `rule/chart-status-not-conditionals`: When the data is loading or failed, pass `status` and `onRetry` to the chart instead of swapping it for a spinner or a message, because the chart keeps its box, waits 250ms before it shows the Skeleton, and announces a failure once. Evidence: person D39; person D37; principle heuristic: visibility of system status. Check: test `chart.test.tsx` expects `aria-busy` with no Skeleton before the wait, and the Retry button on failure.
  - Don't: `{loading ? <Spinner /> : <LineChart ... />}`
  - Do: `<LineChart status={query.status} onRetry={query.retry} ... />`

### Content
- Follows `rule/writing-no-invented-numbers`.
- `rule/chart-change-has-a-sign`: When a change is shown, write it through `ChartChange` with its sign and its arrow, and set `positive="down"` where a fall is good news, instead of a coloured number alone, because colour is never the only cue and a rise in costs is not good news. Evidence: principle wcag: 1.4.1 Use of color; person D13. Check: test `chart.test.tsx` expects "+2.4%" with an up arrow, and `text-good` for a fall when `positive="down"`.
  - Don't: `<span className="text-good">2.4%</span>`
  - Do: `<ChartChange value={2.4} />`

### Anti-slop
- `rule/chart-no-entrance-animation`: When a `BarChart` or `LineChart` appears or its `data` changes, draw the marks in place instead of growing bars or tracing lines in, because nothing in the system scales and a drawing animation delays the number a person came to read; new data only fades in, through the frame's `version`. Evidence: person D36; principle heuristic: the more often seen, the quieter it is. Check: review of every chart file for `transition` or `animate` on a mark's geometry; the only motion is opacity, at `duration-press` for a dim and the frame's crossfade for new data.
  - Don't: `<path className="animate-[grow_600ms]" />`
  - Do: `<BarChart ... />`
- `rule/chart-series-colours-in-order`: When a chart has more than one series, let the chart take `--chart-1` to `--chart-6` in order instead of passing hues of its own, because the order is what keeps neighbours apart for colour-blind readers and keeps a series' colour when another is hidden. Evidence: measured adjacent CVD delta E 14.6 light and 10.8 dark with the validator, docs/system/colors.md; person D13. Check: test `chart-math.test.ts` checks the order and 3:1 on the card in both themes.
  - Don't: `<span style={{ background: "oklch(0.6 0.2 140)" }} />`
  - Do: `<ChartLegend items={series.map((s, i) => ({ ...s, ...seriesColor(i) }))} />`

### Limits
- `rule/chart-six-series`: When a chart would draw more than 6 series, fold the smallest into an "Other" series or split it into small charts, because past six the colours repeat (dashed on a line, faded on a bar) and the tooltip lists only the top 7 with a count of the rest. Evidence: measured 12 series in .design-system/tmp/charts/line-chart-worst-hover-1-1440-light.png, the tooltip cut to 7 rows and "5 more". Check: review of every `series` array longer than six.
  - Don't: `<LineChart series={twelveStrategies} ... />`
  - Do: `<LineChart series={[...topFive, other]} ... />`
- `rule/chart-canvas-past-5000`: When a scatter chart or a heatmap holds more than 5,000 marks, let it paint them on its canvas, which it does by itself, instead of forcing SVG marks, because one SVG node per mark takes more than a frame past that count. Evidence: measured 6.7ms for 5,000 SVG circles and 30.6ms for 20,000, docs/research/2026-10-17-charts.md; measured hover median 3ms on 100,000 points, .design-system/evidence/charts/hover-cost.jsonl. Check: test `scatter-chart.test.tsx` expects the 5,000 threshold.
  - Don't: `points.map((p) => <circle cx={p.x} cy={p.y} />)`
  - Do: `<ScatterChart data={points} ... />`

## Accessibility
Rests on a focusable `div` with `role="group"` and `aria-roledescription="chart"`, one tab stop per chart. The marks are `aria-hidden`; the data is a visually hidden sentence (`aria-describedby`) and a visually hidden `table`, sampled to 200 evenly spaced rows with a note past that. Series colours hold 3:1 on the card in both themes (test). The tooltip text is `--tip-foreground` on `--tip`, the tooltip's own pair. Screen reader pass with VoiceOver: NEEDS REVIEW.

### Keyboard
| Key | Where focus is | Effect | Focus after | Checked by |
|---|---|---|---|---|
| Tab | before the chart | focuses the box and shows the last point | the box | by hand |
| Right, Left | the box | the next or previous point; on a heatmap, the next or previous column | the box | by hand |
| Down, Up | a heatmap | the next or previous row | the box | by hand |
| Home, End | the box | the first or the last point | the box | by hand |
| Page Down, Page Up | the box | a tenth of the points on or back, at least 2 | the box | by hand |
| Escape | the box, or the pointer over it | hides the crosshair and tooltip | stays | by hand |
| Tab | the box | leaves the chart; the legend buttons come next | the next control | by hand |

### ARIA
| Part | Role | Accessible name from | States and properties | Announced | Checked by |
|---|---|---|---|---|---|
| box | group | `label`, through `aria-label`; `aria-roledescription` from `labels.chart` | `aria-describedby` the summary; `aria-busy` while pending | the name, "chart" and the summary when it is reached | test |
| live line | none, `aria-live="polite"` | nothing | none | the point and each series' value as the keys move; pointer moves are silent | by hand |
| table | table | its caption, the `label` | a row header per point | read on request from the table list | test |
| legend item | button | its series name | `aria-pressed` | the name and pressed or not | test |
| failure | alert | its title | none | "Could not load the chart" once | test |

## Tokens
| Part | State | Token |
|---|---|---|
| series | all | `--chart-1`, `--chart-2`, `--chart-3`, `--chart-4`, `--chart-5`, `--chart-6` |
| comparison series | all | `--chart-previous` |
| gridlines | all | `--chart-grid` |
| zero line | all | `--border` |
| axis labels | all | `--muted-foreground` |
| crosshair | hover | `--foreground` at 15% |
| marker ring | hover | `--card` |
| tooltip | hover | `--tip`, `--tip-foreground`, `--edge` as the 1px ring, `--r-md`, `--t-press`, `--curve`; the 8px gap is `TOOLTIP_OFFSET` from `registry/cobalt/ui/tooltip.tsx` |
| cell outline | hover | `--foreground` |
| change chip | all | `--good`, `--bad`, `--muted`, `--r-sm` |
| legend swatch | all | `--r-xs` |

## Related
- Stat: one figure and its change, with no chart.
- BarList: ranked names whose values are read one by one.
- ChartCard: a card with the chart's title and headline figure.
