---
title: UI kit - Charts
summary: The @spacemix/ui charts - Sparkline, BarChart, LineChart, DonutChart, Heatmap and Gauge, with ChartLegend and ChartTooltip - drawn in SVG with the series colors, with their data shapes, props and accessibility.
audience: both
stability: experimental
since: protocol 1
---

# Charts

Line, area, bar, donut, heatmap, gauge and sparkline charts, drawn in SVG with the six series colors (`--op-c1` to `--op-c6`, Tailwind `c1` to `c6`), so they match the widget frame's charts. There is no chart library. Source: `packages/ui/src/charts.tsx`.

Every chart follows the light and dark theme, takes its width from its container, and gives screen readers the data as a hidden table (named by `label`), so every value is reachable without the pointer. The bar, line and donut charts and the heatmap show a tooltip on hover and on arrow-key focus. Every chart takes the native props of its root element, `className` joined last and `ref`. The [conventions](../ui.md#conventions) apply.

**Stability:** experimental, every export on this page: new in this release, and names and props may still be adjusted before they are promised.

## Data shapes

```ts
type SeriesColor = "c1" | "c2" | "c3" | "c4" | "c5" | "c6";   // c1 follows the accent

/** One series of a BarChart or LineChart. */
interface ChartSeries {
  key: string;            // the field of each row holding this series' value
  label?: string;         // the name in the legend, tooltip and data table; default `key`
  color?: SeriesColor;    // default the next series color, c1 first
}

/** One row: the `index` field (a label or a date string) and a number per series. */
type ChartDatum = Record<string, string | number | null | undefined>;
```

`SeriesColor`, `ChartSeries` and `ChartDatum` are exported.

## `BarChart`, `LineChart`

`BarChart` draws bars for comparing categories: vertical or horizontal, grouped or stacked. `LineChart` draws lines over time or a sequence, one per series, with an area option, a smooth curve and gaps for missing (`null`) values. Both have gridlines, a legend that toggles series, and a hover and keyboard tooltip. `lucide-react` also has `BarChart` and `LineChart` icons; import them as `BarChartIcon` and `LineChartIcon`.

```tsx
<LineChart
  data={[{ month: "Jan", signups: 120, churn: 8 }, { month: "Feb", signups: 180, churn: 11 }]}
  index="month"
  series={[{ key: "signups", label: "Sign-ups" }, { key: "churn", label: "Churn", color: "c4" }]}
  label="Sign-ups and churn by month"
/>
```

Props both take:

| Prop | Type | Default | What it does |
|---|---|---|---|
| `data` | `ChartDatum[]` | required | The rows, one per category or point in time. |
| `index` | `string` | required | The field of each row that names it (the x axis): `"month"`, `"date"`. |
| `series` | `ChartSeries[]` | required | The series to draw. |
| `height` | `number` | `240` (a horizontal `BarChart` grows with its rows) | In px; the width follows the container. |
| `valueFormat` | `(value: number) => string` | the locale's number, at most 2 decimals | Formats values in the tooltip and the data table. Axis ticks are always compact ("1.2K"). |
| `indexFormat` | `(value: string) => string` | `String` | Formats the index labels on the axis and in the tooltip. |
| `showLegend` | `boolean` | when there is more than one series | The legend under the chart, which also toggles series. |
| `showGrid` | `boolean` | `true` | Horizontal gridlines at the value ticks. |
| `showValueAxis` | `boolean` | `true` | The value axis labels. |
| `showIndexAxis` | `boolean` | `true` | The category axis labels. |
| `tooltip` | `boolean` | `true` | The hover and keyboard tooltip. |
| `label` | `string` | `"Chart"` | Names the chart for screen readers (the data table's caption). |
| `empty` | `ReactNode` | `"No data yet"` | Shown instead of the chart when there is no data. |

`BarChart` also takes:

| Prop | Type | Default | What it does |
|---|---|---|---|
| `orientation` | `"vertical" \| "horizontal"` | `"vertical"` | Bars up from the bottom, or along from the left (long category names, rankings). |
| `layout` | `"grouped" \| "stacked"` | `"grouped"` | Series side by side, or stacked into one bar per category. |

`LineChart` also takes:

| Prop | Type | Default | What it does |
|---|---|---|---|
| `area` | `boolean` | none | A soft fill under each line. |
| `curve` | `"linear" \| "smooth"` | `"linear"` | Straight segments, or a smooth curve that never overshoots the data. |
| `showDots` | `boolean` | `false` | A dot on every point, not only the hovered one. |
| `zeroBased` | `boolean` | `true` | Starts the value axis at zero; turn off for values far from zero (temperatures, prices). |

`BarChartProps` and `LineChartProps` are the props types.

## `Sparkline`

A tiny trend line (or bars) without axes, for a `Stat`, a table cell or a list row.

| Prop | Type | Default | What it does |
|---|---|---|---|
| `data` | `(number \| null)[]` | required | The values, oldest first; `null` leaves a gap. |
| `variant` | `"line" \| "area" \| "bar"` | `"line"` | A line, a line over a soft fill, or bars. |
| `tone` | `Tone` | `"accent"` | What the trend means: `"success"` for a good one, `"danger"` for a bad one, `"neutral"` for no judgement. `"accent"` is the same color as series `c1`. A sparkline stands alone, so it takes a `tone`, not a series `color`. |
| `height` | `number` | `32` | In px; the width follows the container. |
| `showLast` | `boolean` | `true` for lines | A dot on the last value. |
| `label` | `string` | `"Trend from <first> to <last>"` | The accessible summary. |

`SparklineProps` is the props type.

## `DonutChart`, `DonutSlice`

```ts
interface DonutSlice { key?: string; label: string; value: number; color?: SeriesColor }  // key defaults to the label; color to the next series color
```

Shares of a whole as a ring (or a pie), with the total in the middle, a legend with values, and a hover and keyboard tooltip.

| Prop | Type | Default | What it does |
|---|---|---|---|
| `data` | `DonutSlice[]` | required | The slices. |
| `diameter` | `number` | `160` | The ring's diameter in px; it shrinks to fit a narrow container. |
| `thickness` | `number` | `0.28` | The ring's width as a share of the radius, 0.1 to 1 (1 is a pie). |
| `centerValue` | `ReactNode` | the total | In the middle; the hovered slice's value shows instead while one is hovered. |
| `centerLabel` | `ReactNode` | `"Total"` | Under the center value. |
| `valueFormat` | `(value: number) => string` | the locale's number, at most 2 decimals | Formats values in the middle, the legend, the tooltip and the data table. |
| `showLegend` | `boolean` | `true` | The legend beside the ring, with each slice's value. |
| `label` | `string` | `"Chart"` | Names the chart for screen readers. |
| `empty` | `ReactNode` | `"No data yet"` | Shown instead when every value is zero. |

`DonutChartProps` is the props type.

## `Heatmap`, `HeatmapDatum`

```ts
interface HeatmapDatum { date: Date | string; value: number }  // date: a Date or an ISO date string ("2026-10-28")
```

A calendar grid of days shaded by value (a contribution graph), for activity over weeks or a year. It scrolls sideways on narrow screens and is readable by keyboard.

| Prop | Type | Default | What it does |
|---|---|---|---|
| `data` | `HeatmapDatum[]` | required | Values per day; days not listed count as 0, the same day twice adds up. |
| `end` | `Date \| string` | today | The last day shown. |
| `weeks` | `number` | `26` | How many weeks back from `end`; 53 is a year. |
| `weekStart` | `0 \| 1` | `1` | 0 starts weeks on Sunday, 1 on Monday. |
| `color` | `SeriesColor` | `"c1"` | The color of the fullest cells. |
| `levels` | `number` | `5` | Shades from empty to full (empty and four steps). |
| `cellSize` | `number` | `11` | A cell's side in px. |
| `valueFormat` | `(value: number) => string` | the locale's number, at most 2 decimals | Formats a value in the tooltip, such as `(n) => n + " commits"`. |
| `showLabels` | `boolean` | `true` | Month names above and day names beside. |
| `showLegend` | `boolean` | `true` | "Less … More" under the grid. |
| `label` | `string` | `"Activity"` | Names the chart for screen readers. |
| `locale` | `string` | the browser's | For month and day names. |

`HeatmapProps` is the props type.

## `Gauge`, `GaugeThreshold`

```ts
interface GaugeThreshold { value: number; tone: Tone }  // from this value up, the gauge takes this tone
```

A half-circle dial for one value in a range (CPU, a score, a budget), turning tone past thresholds. It scales with its width (`w-40` by default; set another width in `className`). `lucide-react` also has a `Gauge` icon; import it as `GaugeIcon`.

| Prop | Type | Default | What it does |
|---|---|---|---|
| `value` | `number` | required | The value. |
| `min` | `number` | `0` | The range's start. |
| `max` | `number` | `100` | The range's end. |
| `tone` | `Tone` | `"accent"`, unless a threshold applies | The arc's color. |
| `thresholds` | `GaugeThreshold[]` | `[]` | Tones by value, lowest first: `[{ value: 70, tone: "warning" }, { value: 90, tone: "danger" }]`. |
| `label` | `string` | none | Under the value: what is measured. Also the accessible name. |
| `valueFormat` | `(value: number) => string` | the percentage of the range | Formats the value in the middle and for screen readers. |
| `showRange` | `boolean` | `true` | The min and max under the arc's ends. |

`GaugeProps` is the props type. For a bar, see [`Meter`](data-display.md#meter).

## `ChartLegend`, `ChartLegendItem`

```ts
interface ChartLegendItem { key: string; label: ReactNode; color?: SeriesColor; value?: ReactNode }  // value: after the label (a donut's share)
```

The key to a chart's colors, for a chart you draw yourself; with `onHiddenChange` each entry is a toggle button (`aria-pressed`) that switches its series on and off.

| Prop | Type | Default | What it does |
|---|---|---|---|
| `items` | `ChartLegendItem[]` | required | The entries; `color` defaults to the next series color. |
| `hidden` | `string[]` | none | Keys of the series switched off (controlled). |
| `defaultHidden` | `string[]` | `[]` | Keys switched off to start with. |
| `onHiddenChange` | `(keys: string[]) => void` | none | Makes the entries toggles and reports the keys switched off. |
| `orientation` | `"horizontal" \| "vertical"` | `"horizontal"` | A row that wraps, or one per line with values on the right. |

`ChartLegendProps` is the props type.

## `ChartTooltip`, `ChartTooltipItem`

```ts
interface ChartTooltipItem { label: ReactNode; value: ReactNode; color?: SeriesColor }  // color: a swatch before the label
```

The value panel that follows the pointer (or the keyboard) over a chart, rendered through a portal. It is decorative to screen readers, which read the chart's data table instead.

| Prop | Type | Default | What it does |
|---|---|---|---|
| `open` | `boolean` | `true` | Whether it shows. |
| `anchor` | `FloatingAnchor \| null` | required | What it hangs off: the hovered point (viewport coordinates) or an element. See [`FloatingAnchor`](overlays.md#floating-types). |
| `title` | `ReactNode` | none | The heading: the category or date. |
| `items` | `ChartTooltipItem[]` | required | The lines. |
| `side` | `Side` | `"top"` | Flips when there is no room. |
| `className` | `string` | none | Classes for the panel. |

`ChartTooltipProps` is the props type.
