Skip to content

Donut Chart for React

An animated React donut chart with the total in the center, a full legend and keyboard-readable slices. Pass data as readonly DonutSlice[]: part-to-whole only, at most 6 slices: fold the rest into "Other".

npx shadcn@latest add https://lokendra-builds.github.io/sheenui/r/donut-chart.json

Traffic sources

Use arrow keys to read each slice.
95.1KSessions

  • DonutChart
  • DonutTable
  • defaultDonutChartLabels
  • defaultDonutTableLabels
  • +2 more

Donut chart with a center total

Hover a slice to read it in the center. Click a legend key to leave a slice out; the ring re-flows and the total re-counts.

Traffic sources

Sessions this month

Use arrow keys to read each slice.
95.1KSessions

Files to copy

11 folders · 24 files · 4 packages
From theme/src/
  • components/charts/{donut-chart.tsx, chart-export-menu.tsx, chart-export.ts, chart-figure.tsx, chart-icons.tsx, chart-parts.tsx, chart-patterns.tsx, chart-utils.ts}
  • components/charts/chart-parts/
  • components/drawer/parts/sheet.tsx
  • components/kbd/
  • components/menu/
  • components/skeleton/
  • components/status-icons/
  • hooks/{use-controllable.ts, use-intersection.ts, use-latest.ts, use-media-query.ts, use-preferences.ts}
  • motion/tokens.ts
  • lib/{cn.ts, csv.ts, form.ts, glide-highlight.tsx, heading.ts, math.ts, popup-a11y.ts, popup-motion.ts, warn-once.ts}
  • styles/
shadcn CLI
npx shadcn@latest add https://lokendra-builds.github.io/sheenui/r/donut-chart.jsonRegistry item: donut-chart. The styles need the Tailwind v4 glass UI setup.
Packages
pnpm add @base-ui/react clsx motion tailwind-merge

Next.js: samples here pass functions (formatters, seriesLegend, a dashboard's load), so put them in a file that starts with "use client".

DonutChart props

PropTypeDefaultDescription
data (required)readonly DonutSlice[]NonePart-to-whole only, at most 6 slices: fold the rest into "Other". Negative values count as 0.
diameternumber200Outer diameter of the ring in px; the chart is a circle of this width and height.
format((n: number) => string)compact numbers in localeFormats values in the tooltip and legend.
localestring"en"Locale for the default number format and percentages (e.g. "de").
emptyStateReactNodeNoneShown in the centre when there is nothing to plot (no slices, or every value is 0).
legendTogglebooleantrueLegend items toggle slices (the ring re-flows, the total updates).
hiddenSlicesreadonly string[]NoneSlice keys (or labels) to hide (controlled).
defaultHiddenSlicesreadonly string[][]Slice keys (or labels) hidden at first (uncontrolled).
onHiddenSlicesChange((keys: string[]) => void)NoneCalled with the keys of the hidden slices whenever the legend toggles one.
glowbooleantrueSoft glow on the active slice in dark mode.
patternsbooleantrue when data.length > 3Tell slices apart without colour (hatch fills).
labelsPartial<DonutChartLabels>defaultDonutChartLabelsThe chart's built-in strings (empty state, table text); a partial object over the English defaults, so pass only the keys you translate. Every other string, for translation: labels={{ legend: "…" }}; omitted keys keep the English of defaultDonutChartLabels. All 7 keys of DonutChartLabels are listed in the key table under the props table.
aria-label (required)stringNoneNames the chart for assistive tech (required).
classNamestringNoneAdds extra classes to the outer element.
DonutChartLabels keys and English defaults (7)
Pass any key in labels; the rest keep the defaults of defaultDonutChartLabels.
KeyEnglish default
legendSlices: press to show or hide
shown(label) => `${label} shown`
hidden(label) => `${label} hidden`
instructionsUse arrow keys to read each slice.
noDataSuffixno data
percent(pct) => `${pct} percent`
centerTotal

DonutTable props

PropTypeDefaultDescription
data (required)readonly DonutSlice[]NonePart-to-whole only, at most 6 slices: fold the rest into "Other". Negative values count as 0.
format((n: number) => string)compact numbers in localeFormats values in the tooltip and legend.
localestring"en"Locale for the default number format and percentages (e.g. "de").
formatPercent((ratio: number) => string)percentages in localeFormats a share (0.412 → "41.2%").
captionstringNoneHidden caption that names the table for screen readers.
labelsPartial<DonutTableLabels>defaultDonutTableLabelsHeader and empty-state text; pass only the keys you translate. Every other string, for translation: labels={{ slice: "…" }}; omitted keys keep the English of defaultDonutTableLabels. All 4 keys of DonutTableLabels are listed in the key table under the props table.
classNamestringNoneAdds extra classes to the outer element.
DonutTableLabels keys and English defaults (4)
Pass any key in labels; the rest keep the defaults of defaultDonutTableLabels.
KeyEnglish default
sliceSlice
valueValue
shareShare
noDataNo data

When to use a donut chart

A React donut chart, which some teams call a doughnut chart, shows how one total divides into a few parts, such as traffic sources, plan mix or storage by file type. The hole in the middle holds the total, which a plain pie chart has no room for, and the ring stays legible on a glass card.

If the parts are close in size or there are many, a bar chart is easier to compare. See the pie chart, the radial bar chart and the gauge chart for related shapes, or the React bar chart for an exact comparison.

Frequently asked questions

All exports on this page

  • DonutChart — A donut for the share of a whole, with a centre label (labels.center, default "Total") and a legend that can hide slices.
  • DonutTable — The table view of a DonutChart: every slice with its value and its share of the total.
  • defaultDonutChartLabels — The built-in English strings of DonutChart; spread it into your own labels and change what you need.
  • defaultDonutTableLabels — English defaults of DonutTableLabels.

Keyboard

KeysAction
TabMove through the Chart / Table tabs, then the legend keys, then the chart itself.
← → (↑ ↓)Read the previous or next point; the values are announced.
Home/EndJump to the first or last point.
EscapeClear the active point.
Enter/Spaceon a legend keyHide or show that series.

Accessibility

  • Tab focuses the ring as one stop; the arrow keys step slice by slice and announce the label, the value and its share of the total.
  • The center total is text, not an image, and the Chart / Table tabs switch to a DonutTable with slice, value and share columns.
  • Legend entries are toggle buttons (Enter or Space) that hide a slice; with more than three slices each gets its own hatch (patterns).
  • Reduced motion: the ring appears at its final angles and data changes jump.

48 charts pages in all: browse them on Charts.

By Lokendra Singh Rathore (GitHub, opens in a new tab). Published , updated .