Donut chartPro
Proportions as arcs that morph when the data changes.
pnpm dlx shadcn@latest add @lode/donut-chartVisits by source
Aug 23 – Sep 21, 2026
- Search16,84016,84041%41%
- Direct8,1208,12020%20%
- Newsletter5,2605,26013%13%
- Referrals6,4306,43016%16%
- Social2,9102,9107%7%
- OtherPodcasts and partners1,0501,0503%3%
When to use
- Up to six parts of a whole, like traffic sources or plan mix.
When not to use
- Comparing many similar values: use a bar chart.
- Change over time: use an area or line chart.
Installation
pnpm dlx shadcn@latest add @lode/donut-chartPro components need an API key and the registry in components.json. See CLI and API keys.
1Install the dependencies
npm install motion2Copy the source into your project
Usage
Import it from @/components/ui/donut-chart after installing.
import { DonutChart } from "@/components/ui/donut-chart";
export function Sources() {
return (
<DonutChart
centerLabel="Visits"
data={[
{ label: "Search", value: 16840, color: "var(--chart-1)" },
{ label: "Direct", value: 8120, color: "var(--chart-2)" },
{ label: "Referrals", value: 6430, color: "var(--chart-4)" },
]}
/>
);
}API reference
DonutChart
Proportional arcs with a total in the middle. Hover a segment to see its own value.
data
{ label: string; value: number; color: string }[]
Segments in drawing order, clockwise from 12 o'clock.
size / thickness= 240 / 30
number
Max diameter and ring width in px. Shrinks to fit narrower containers.
gap= 2.5
number
Gap between segments in degrees.
centerLabel / format= "Total"
string / (n) => string
Center caption and number format.
activeIndex / onActiveIndexChange
number | null
Control the highlight, e.g. from a legend list.
| Prop | Type | Default | Description |
|---|---|---|---|
| data | { label: string; value: number; color: string }[] | – | Segments in drawing order, clockwise from 12 o'clock. |
| size / thickness | number | 240 / 30 | Max diameter and ring width in px. Shrinks to fit narrower containers. |
| gap | number | 2.5 | Gap between segments in degrees. |
| centerLabel / format | string / (n) => string | "Total" | Center caption and number format. |
| activeIndex / onActiveIndexChange | number | null | – | Control the highlight, e.g. from a legend list. |
Accessibility
- The SVG has role="img" labelled with the total.
- Always pair it with a legend that lists exact values; color is not enough on its own.
Motion
- Arcs sweep in from 12 o'clock, then interpolate start and end angles when data changes (800ms).
- Hover thickens a segment and dims the others.
Responsive behavior
- Square, fills its container up to size.
Performance
- Arc paths are computed per frame only during the 800ms transition.
Notes for AI
- Use var(--chart-1) to var(--chart-6) so colors follow the theme.
- Keep labels unique; they're used as keys.
This page as Markdown, for assistants and coding agents:
/components/donut-chart/markdownThe full library index for assistants is at /llms.txt.
Related
Lode·229 doc pages·llms.txt