Skip to content
Thrum

Donut chart

Parts of a whole as a ring, with the total in the middle. Use it for two to five parts whose shares matter more than their exact sizes: traffic by source, spend by team. When the parts have to be compared closely, use the bar chart.

Install

npx shadcn@latest add @thrum-pro/donut-chart

This is a Pro component. The command works once your project has a licence key: set up Pro or see pricing.

Data shape

Type
type DonutChartSegment = {
  name: string;  // shown in the legend
  value: number; // zero and below is left out
};
Sample
[
  { name: "Direct", value: 4210 },
  { name: "Organic search", value: 2480 },
  { name: "Referral", value: 1390 },
  { name: "Social", value: 920 },
]

Props

PropTypeDefaultDescription
datareadonly DonutChartSegment[]RequiredThe parts, drawn clockwise from 12 o'clock in the order given. They are never sorted. Past five, the rest are added up and drawn as one neutral segment named Other.
labelstringRequiredWhat the whole measures. Shown under the total, read by screen readers and used as the table caption.
formatIntl.NumberFormatOptionsDefault compactHow values are written in the centre, in the legend and in the data table. Shares are whole percentages that add up to 100.
localestringDefault "en-US"Locale for numbers and percentages. Fixed by default so the server and the browser print the same text.
total"sum" | "none"Default "sum"What the centre shows while no segment is under the cursor: the sum of the parts with the label, or nothing. The segment under the cursor always shows its value and share there.
thicknessnumberDefault 16Width of the ring in pixels. It is capped at a quarter of the ring's diameter.
legendbooleanDefault trueList every segment with its colour, name, value and share. The list sits beside the ring, or below it when there is no room.
onActiveChange(index: number | null) => void–Called with the index of the segment under the cursor, or null when the cursor leaves. The index counts the segments drawn: parts at zero or below are skipped, and Other is index 5.
soundbooleanDefault truePlay a tick as the cursor moves between segments, if the visitor has sound on.
emptyLabelstringDefault "No data"Text shown inside an empty ring when no part has a value above zero.
classNamestring–Sets the width. The default is full width. The ring takes the room the legend leaves: 112 to 192 pixels across, and less only when the whole component is narrower than that.

Motion and sound

Motion

  • First draw: the ring is swept in clockwise from 12 o'clock in 700 ms at constant speed, and the total rolls up from zero.
  • New values with the same number of segments: each segment slides along the ring to its new size in 400 ms with no overshoot, and the total rolls to the new sum. A different number of segments switches at once.
  • The segment under the cursor is drawn 6 pixels thicker. No other segment is dimmed.
  • Reduced motion: the ring and the total appear complete, and changes are instant.

Sound

  • A soft tick each time the cursor lands on a different segment, at most one every 40 ms.

Sound is off until the visitor turns it on. Pass sound={false} to keep this component silent. How sound works

Accessibility

  • The ring is one tab stop. It is exposed as a slider whose value text is the segment under the cursor, for example “Direct: 4,210, 42%”.
  • A visually hidden table carries every segment with its value and share, with the label as its caption. The legend repeats it for the eye and is hidden from screen readers.
  • Colour is never the only key: each segment is named in the legend, and its name, value and share appear in the centre while the cursor is on it.
  • Segments are separated by a 2 pixel gap, and a part too small to see is drawn 2 pixels wide so it can still be found. Its share reads “<1%”, never “0%”.
  • The ring and 8 pixels inside it are the pointer target. Legend rows mark their segment under the pointer too.
KeysAction
TabFocus the ring. The cursor goes to the last segment.
← →Move the cursor one segment, anticlockwise or clockwise.
Home / EndJump to the first or last segment.
EscHide the cursor and show the total again.

Source

SourcePro

The source comes with Pro

TypeScript source · Copy-paste ready · MIT-compatible for client projects · Includes all dependencies

Files and dependencies

Adds
components/ui/donut-chart.tsx
Packages
motion
Brings along
Chart foundationsMotion tokensSound engineAnimated number

Changelog

  1. 1.0.1 · 2026-12-03Corners follow the project's --radius, down to square.
  2. 1.0.0 · 2026-12-02First release.

Loading index…

Keyboard shortcuts

/Ctrl KSearch components, docs and actions
?Show this list
AAppearance studio
SSound on or off
MFull or reduced motion
TTheme: auto, light, dark
GSurface: solid or frosted
BBackdrop photograph (under glass)
CCorner radius: square to round
RReplay the demo, on a component page
DDraw new data, on a component page
←→HomeEndMove the cursor in a focused chart
EscClose a dialog, or leave a chart cursor