# MicroDonut (/docs/charts/micro-donut)

A KPI card prints "62% Chrome" and wants a mix icon beside it. MicroDonut is that icon: a ring at icon size showing
roughly what something is made of. For any comparative read, use [SegmentedBar](/docs/charts/segmented-bar) instead — a
flat bar beats a donut of the same data at every size we ship. The wedge cap and the labeled rollup are non-optional,
and so is the hole: a ring encodes angle and arc length together, which is the read a pie's area can't match, and the
reason pie stays unshipped. Nothing here is exploded, tilted, or shadowed.

```tsx
<MicroDonut
  data={[
    { label: "Chrome", value: 620 },
    { label: "Safari", value: 240 },
    { label: "Firefox", value: 90 },
    { label: "Edge", value: 30 },
    { label: "Arc", value: 20 },
  ]}
  size={48}
  title="Traffic mix"
  style={{ width: 72, height: 72 }}
/>
```

## Install

```tsx
import { MicroDonut } from "@microcharts/react/micro-donut";

<MicroDonut data={mix} title="Traffic mix" />
```

Setup (package + stylesheet): [Quickstart](/docs/quickstart#set-up-with-an-ai-agent) or paste [`/agent-setup.md`](/agent-setup.md) into your agent.

## Try it

```tsx
import { MicroDonut } from "@microcharts/react/micro-donut/interactive";

<MicroDonut
  data={mix}
/>
```

## When to use it

Use it for a mix icon beside the printed headline number in a KPI card. For any comparative read use SegmentedBar; these
docs steer there first.

## Sizing

**beside the printed number**

```tsx
// the number is the datum; the donut repeats it — declare it decorative
<span>62% Chrome <MicroDonut data={mix} decorative /></span>
```

**accessible mix icon**

```tsx
<MicroDonut data={mix} title="Traffic mix" />
```

## Variants

```tsx
// the number is printed next to it; the donut repeats it
const mix = [
  { label: "Chrome", value: 620 },
  { label: "Safari", value: 240 },
  { label: "Firefox", value: 140 },
];

<span>62% Chrome <MicroDonut data={mix} decorative /></span>
```

## Edge cases

```tsx
<MicroDonut data={[{ label: "Chrome", value: 620 }]} title="All Chrome" />
```

```tsx
<MicroDonut data={[]} title="Empty" />
```

A single category fills the ring, and that full annulus looks like a 100% ProgressRing; the summary names the category
and its share, which is what tells the two apart. Empty data draws no wedges.

## Four homes

**In a sentence**

```tsx
// the number is the datum; the donut repeats it — declare it decorative
<p>
  Chrome carried 62% of this week's sessions{" "}
  <span className="mc-inline">
    <MicroDonut data={mix} decorative summary={false} />
  </span>{" "}
  — the rest split across four browsers.
</p>
```

**In a table cell**

```tsx
<td>
  <MicroDonut data={mix} style={{ width: 18, height: 18 }} />
</td>
```

**In a KPI card**

```tsx
<div className="kpi">
  <span className="figure">1,000</span>
  <span className="unit">62% Chrome</span>
  <MicroDonut data={mix} title="Traffic mix" />
</div>
```

**In a tab header**

```tsx
<button className="tab">
  Desktop <MicroDonut data={mix} style={{ width: 14, height: 14 }} />
</button>
```

## Accessibility

The accessible name is the full composition, worded the same as SegmentedBar. `decorative` marks the chart `aria-hidden`
for the one sanctioned ornamental use, beside a printed value, and the interactive entry refuses to make a decorative
donut a tab stop.

The interactive entry follows the shared [interaction contract](/docs/accessibility#one-interaction-contract):
arrow keys rove between units on both axes, `Home` and `End` jump to the ends, and a click, tap, `Enter` or
`Space` selects a unit — pinning its readout so it survives blur, until you select it again, press `Escape`, or
press outside the chart. On touch, a tap pins and a drag scrubs.

## Props

| Prop | Type | Description |
| --- | --- | --- |
| `data` (required) | `{ label; value }[]` | Parts of the whole. |
| `maxWedges` | `number` | Rollup threshold (default 4). |
| `decorative` | `boolean` | Redundant ornament beside a printed value → aria-hidden. |
| `weight` | `number` | Annulus thickness (shared with ProgressRing). |
| `label` | `"none" \| "total"` | Center total when the hole has room (default "none"). |
| `colors` | `string[]` | Per-wedge colours, cycled; overrides --mc-cat-N. Other stays neutral. |
| `size` | `number` | Donut square edge in viewBox units (default 24). |
| `animate` | `boolean` | (interactive) Opt-in entrance motion when the chart mounts client-side — add `import "@microcharts/react/motion"` once. Inert on the server, on hydrated server HTML, and under `prefers-reduced-motion`. |

Plus the shared grammar — `data`, `domain`, `color`, `title`, `summary`, `format` — and the layout props (`width`, `height`, `className`, `style`) that every chart accepts. Interactive entries also share `animate` and `live`, and — wherever a chart has more than one navigable unit — `onActive`, `onSelect`, `selectedIndex` and `defaultSelectedIndex`; and — wherever the chart shows a hover value — `readout`. See [the shared grammar](/docs/quickstart#the-shared-grammar).
