Parts of a whole as a ring, with a legend of every value and share. Plain SVG, no chart library.
$ pnpm dlx shadcn@latest add https://dashral.com/r/donut-chart.jsonInstallation
$ pnpm dlx shadcn@latest add https://dashral.com/r/donut-chart.jsonAdds the component, the components it builds on, its npm packages and the theme tokens it uses. Using Dashral often? Add the registry to components.json once:
components.json
{
"registries": {
"@dashral": "https://dashral.com/r/{name}.json"
}
}Then add components by name:
$ pnpm dlx shadcn@latest add @dashral/donut-chartUsage
example.tsx
import { DonutChart } from "@/components/dashral/donut-chart"
<DonutChart
data={[
{ label: "Direct", value: 420 },
{ label: "Search", value: 310 },
{ label: "Social", value: 120 },
]}
aria-label="Visits by source"
/>Examples
API reference
DonutChart
Also takes every prop of <div>(opens in a new tab).
| Prop | Type | Default |
|---|---|---|
data | { label: string; value: number; color?: string }[]The slices. Colors default to --chart-1 … --chart-5. Required. | — |
children | ReactNodeIn the middle, e.g. the total. | — |
size / thickness | numberDiameter and ring width in pixels. | 160 / 20 |
showLegend | booleanThe list of values and shares (kept for screen readers when hidden). | true |
locale / formatOptions | string / Intl.NumberFormatOptionsHow values are written. | LocaleProvider's |
aria-label | stringWhat the chart shows. | "Donut chart" |
Accessibility
- The ring is role="img" with your label; the legend lists every value and percentage as text, so nothing depends on color.
- Each slice has a tooltip; the value shown in the middle on hover is announced politely.
Motion
- Slices sweep in when it first shows; instant with reduced motion.