Pie Chart
Show how a whole splits into parts with a pie or a donut.
Use a pie chart to show a few parts of one total, like hours by team or budget by category. Keep it to a handful of slices; for more, or to compare totals, use a bar chart.
Installation
npx shadcn@latest add @kind-ui/pie-chartComposition
PieChart
├── PieChart.Series
│ ├── PieChart.Cell
│ └── PieChart.Labels
├── PieChart.Tooltip
├── PieChart.Legend
└── PieChart.ContentPieChart holds the series config and the accessible name, and draws only the parts you add. PieChart.Series draws one sector per row. PieChart.Labels writes a row field on each sector, and PieChart.Cell paints one sector by hand. PieChart.Content places your own HTML next to the legend.
Usage
Categories
Each row is a category. Set categoryKey on the series to the field holding the category's config key: the sector takes its color from there, and the tooltip and legend use its label. dataKey is the value that sizes the sector, and nameKey is what the tooltip reads, so point it at the same field. Give PieChart.Tooltip an itemKey that returns the same key.
List every category in interaction.eligibleKeys, including any with a value of 0, so the legend can reach them.
Donut and Rounded Sectors
Set innerRadius for a donut. cornerRadius rounds the sector ends, and paddingAngle adds a gap in degrees between sectors. Keep the total padding well under the full circle; very thin sectors lose their rounding.
Legend and Keyboard
By default, pressing a legend item highlights its slice and dims the others, and screen readers hear "Highlighted Design." Press it again, or press Escape, to clear it. Pressing a slice does the same.
With interaction={{ kind: "category", mode: "visibility", ... }} and defaultVisibleSeries, the legend hides and shows slices instead, and screen readers hear "Hidden Design." A hidden slice keeps its angle, so the others don't move, and the last visible slice can't be hidden. Pass visibleSeries and onVisibleSeriesChange to control it yourself. See Legend.
Focus the chart and press the arrow keys to move between slices, which shows the tooltip, and Escape to dismiss it.
Open Tooltip
Set defaultPinnedCategory to open one category's tooltip on mount, like the largest share. It follows that category if the rows reorder, and closes for good as soon as the reader hovers, focuses or presses a key:
<PieChart defaultPinnedCategory="design" {...props}>Materials
Set material="clay" or "glow" on the series for a finish on every sector, or glowCategories={["design"]} to make only some of them glow. See Materials.
Motion
With animate, the sectors sweep in when the chart mounts. Set animationDirection="anticlockwise" to reverse the sweep, and pass animate={{ revealDurationMs: 800 }} to change its length. When the reader prefers reduced motion, the sectors appear without sweeping in. See Motion.
Loading
Set loading while the data is on its way. The chart keeps its size and shows a placeholder pie that sweeps around the circle, or holds still when the reader prefers reduced motion. Screen readers hear loadingLabel ("Loading chart" by default):
<PieChart loading={isPending} loadingLabel="Loading allocation" {...props}>API Reference
PieChart
Prop
Type
PieChart.Series
Prop
Type