Pie Chart
ProPie and donut charts for shares of a whole: pies, donuts, half and nested rings, rose and polar bars, labelled and exploded pies.
Playground Pie Charts
Traffic sources
| name | Value |
|---|---|
| Direct | 42% |
| Referral | 26% |
| Social | 18% |
| Other | 14% |
Playground Pies
Traffic sources
| name | Value |
|---|---|
| Direct | 42% |
| Referral | 26% |
| Social | 18% |
| Other | 14% |
Playground Half and polar
Traffic sources
| name | Value |
|---|---|
| Direct | 42% |
| Referral | 26% |
| Social | 18% |
| Other | 14% |
Installation
Pie Chart comes with WunderUI Core and Pro, in the package from your plan. See the plans.
The charts live in their own entry point: import the chart, its card and its hooks from @wunderui/react/charts, not from @wunderui/react.
Then import what you need:
import {
PieChart,
PieChartProps,
PieChartVariant,
} from "@wunderui/react/charts"Then use it:
import { PieChart } from "@wunderui/react/charts"
const data = [
{ name: "Direct", value: 42 },
{ name: "Referral", value: 26 },
{ name: "Social", value: 18 },
{ name: "Other", value: 14 },
]
export function TrafficSources() {
return <PieChart data={data} index="name" label="Traffic sources" />
}Expected result: You should see a pie of four slices. Hovering a slice shows its name, value and share.
When to use
Use Pie Chart for
- The shares of one whole at one moment, with five slices or fewer
- A donut with the total or the hovered value in the centre
- Goals as concentric rings, or values around a circle (rose, polar bar)
Use something else for
- Bar Chart for comparing values, or more than five categories
- Stacked Chart for shares of a whole over time
- Radial Chart for progress against a goal
- Treemap for parts of a hierarchy
States
Loading, empty and error keep the chart's size, so the card never jumps. Add a retry handler and the error state offers a Try again button.
Traffic sources
| name | Value |
|---|---|
| Direct | 42% |
| Referral | 26% |
| Social | 18% |
| Other | 14% |
Indigo tones and pattern donut
The indigo palette colours the slices in one hue, from indigo 600 for the largest slice down to the lighter steps, with a card-coloured gap between neighbours; the light tones leave their values to the legend and the tooltip. The pattern donut tells its parts apart without any hue: solid, stripes and dots in one indigo ring with rounded corners. Several pattern forms in one chart are an owner exception for this donut (the rule is one form per chart); a slice too small for its pattern falls back to solid.
Traffic sources
| name | Value |
|---|---|
| Direct | 42% |
| Referral | 26% |
| Social | 18% |
| Other | 14% |
Centre text
The centre number counts up from zero while the wedges sweep in, then counts to the slice you hover. Its size follows the hole of the ring, so a small card gets a smaller number and the caption shows only when it fits under it.
Traffic sources
| name | Value |
|---|---|
| Direct | 42% |
| Referral | 26% |
| Social | 18% |
| Other | 14% |
Patterns
pattern fills the slices with one form from the shared pattern library — stripes, dots or cross-hatch — drawn in each colour on a tint of it, for print and for readers who cannot tell the colours apart. One form per chart; a mark under 20 px on its shorter side stays solid.
Traffic sources
| name | Value |
|---|---|
| Direct | 42% |
| Referral | 26% |
| Social | 18% |
| Other | 14% |
Keyboard interactions
The plot is focusable: Arrow keys step through the slices in data order and the live region reads name, value and share.
- TaborShift+Tab
- Moves focus to the plot and away from it. The plot is one tab stop; so is every legend badge.
- ArrowRightorArrowLeft
- Moves to the next or previous slice. The tooltip follows, and a live region announces the one you are on. The first press starts at the first one (Left: the last one).
- HomeorEnd
- Jumps to the first or last slice.
- Escape
- Clears the active point.
- EnterorSpace
- On a legend badge of a ChartCard: switches its series off or on. The last visible series stays on.
Behavior and motion
What the chart does on its own and what the page decides.
- Slices
- Each data row is a slice. Name the field for the slice name and the field for the number, and set a colour per row if you like.
- Hit test
- Only the drawn wedge reacts to hover. The hovered slice keeps its strength and the others dim.
- Centre
- A donut shows the total, or the value of the hovered slice, with a label under it. The number counts up as the chart enters and its size follows the hole. You can set the number or pass your own content.
- Small shares
- Ring variants keep a minimum arc length, so a small share stays visible.
- Labels
- The labelled pie writes each slice's name and share on a leader line. When two labels would touch, only the hovered or focused slice keeps its label.
- Tooltip
- The tooltip takes its form from the chart's own width, like Area, Line and Bar: under 360 px it docks over the top of the chart at its full width, under 560 px it is the compact card, above that the standard card that follows the pointer.
- Loading, empty and error
- The chart keeps its size while loading, empty or failed, so the card never changes height. Add a retry handler to show a Try again button on error.
- Legend
- In a ChartCard, each series badge is a button that switches its series off, but the last visible series stays on. A legend of roles can be made static.
- Data table
- The chart renders its data as a table for screen readers, in the same order as the plot.
- Size
- The chart fills the width of its container and you set the plot height. Text never scales, so labels keep their size at every width.
Motion
The enter sequence and the hover follow the motion tokens of the library.
- Sweep
- Wedges sweep in clockwise and rings draw along their arc when the chart first comes into view, after loading and when new data arrives, while the centre number counts up. Nothing turns or pops. The animation can be turned off.
- Hover
- The other slices dim and the centre counts to the hovered value.
- Reduced motion
- With reduced motion on, the chart appears at once without the enter sequence. The tooltip and every state still work.
Anatomy
PieChart shows shares of one whole. The pie and every donut, rose and ring variant are one component, picked with the variant setting.
Traffic sources
| name | Value |
|---|---|
| Direct | 42% |
| Referral | 26% |
| Social | 18% |
| Other | 14% |
- 1
The chart itself. Pass the data, the field names for slice name and value, and optionally colours, ring width and centre content.
- 2data-slot="chart-plot"
The focusable region: Arrow keys step through the slices in data order and the live region reads name, value and share. Only the drawn wedge reacts to hover.
- 3data-slot="chart-marks"
Wedges that sweep in clockwise on first view (their end angles grow) and rings that draw along their arc. While a slice is hovered the others dim; ring variants keep a minimum arc so small shares stay visible. On the nested pie the inner ring hovers and reads like the outer slices.
- Optional
The total, or the value of the hovered slice, with a label under it. It counts up from zero as the chart enters and its size follows the hole of the donut, so a small card gets a smaller number. Pass your own content to replace it.
- data-slot="chart-values"Optional
The labelled pie writes each slice's name and share on a leader line. When two labels would touch, only the hovered or focused slice keeps its label.
- 4data-slot="chart-tooltip"Optional
The slice name with its value and its percent share of the total, anchored to the slice.
- data-slot="chart-message"Optional
A circle or ring skeleton with a shimmer, then the empty and error messages. A pie with all values missing counts as empty.
A table of every slice and value for screen readers. Slices switched off in the legend are marked as hidden.
Best practices
- Do
Sort slices from largest to smallest and keep to five. Group the rest into one Other slice, since thin wedges are hard to compare by angle.
- Do
Prefer a donut with the total in the centre for a headline number, and add a label such as visits or this week to give it a unit.
- Do
Make names readable without colour: use slice labels, a legend or the tooltip. Neighbouring slices in similar hues are hard to tell apart.
- Don’t
Don't use the rose or polar bar for exact values. Radius is read less accurately than length, so they show a pattern, not precision.
- Don’t
Don't pass negative values or parts of different wholes. Negatives draw as zero, and unrelated numbers imply a total that does not exist.
API reference
One table for PieChart, listing every prop. A ChartCard around it takes its own props, and the chart works without one.
The chart itself. Pass the data, the field names for slice name and value, and optionally colours, ring width and centre content.
| Prop | Type | Default | Description |
|---|---|---|---|
| data required | readonly ChartDatum[] | — | One object per slice / ring / axis. |
| index required | string | — | Field holding the label. |
| value | string | — | Field holding the value. Default "value". |
| variant | "pie" | "donut" | "donut-center-label" | "half-donut" | "pad-angle-donut" | "nested-pie" | "multi-ring-donut" | "nightingale-rose" | "labelled-pie" | "polar-bar" | "exploded-pie" | "rounded-arc-donut" | "thin-ring-donut" | "track-ring-donut" | "rounded-half-donut" | "donut" | Figma variant. Default . |
| colors | readonly ChartColor[] | — | Colours per row, in order (palette names or token expressions). |
| centerLabel | string | — | Small text under the centre value ("visits", "this week"). |
| centerValue | number | — | Centre value; defaults to the total (or the hovered slice's value). |
| valueFormatter | ChartValueFormatter | — | |
| label | string | — | Accessible name, e.g. the card title. |
| height | number | — | Height of the plot frame in px. Default 280 (Figma small card plot). |
| state | "ready" | "loading" | "empty" | "error" | — | |
| hiddenSeries | readonly string[] | — | Labels of rows switched off in the legend: drawn faded. |
| palette | "series" | "indigo" | "series" | indigo colours the slices in the indigo tonal scale: 600 for the largest slice, then lighter steps for the smaller ones, with a card-coloured gap between neighbours. The light tones leave their values to the legend and the tooltip. colors still wins. |
| activeIndex | number | null | — | The active point (hovered or focused) as an index into , to control it yourself. shows none. |
| animate | boolean | — | |
| animationKey | string | number | — | |
| center | ReactNode | — | Custom centre content (HTML) instead of the built-in value and label; shows nothing. |
| centerFormatter | (value: number) => string | — | Formats the centre number while it shows the total or centerValue, e.g. visits while the slices are percentages. A hovered slice keeps valueFormatter. |
| defaultActiveIndex | number | null | — | The point that is active at first, for an uncontrolled chart. It shows the tooltip without a pointer. |
| description | string | — | |
| emptyDescription | string | — | Text under the title in the empty state. |
| emptyTitle | string | — | Title of the message in the empty state. |
| errorDescription | string | — | Text under the title in the error state. |
| errorTitle | string | — | Title of the message in the error state. |
| explodeIndex | number | 0 | : the slice pulled out (default 0). |
| innerRadius | number | — | Inner radius as a share of the radius (0…0.95), overriding the variant's ring width. |
| max | number | 100 | : the value of a full ring (default 100). |
| nested | readonly ChartDatum[] | — | : the inner pie's rows (same / fields). They take part in hover, keyboard, tooltip and table. |
| onActiveIndexChange | (index) => void | — | Called with the index when the pointer or the arrow keys move to another point, and with when they leave. Use it to show the hovered value in a headline. |
| onRetry | () => void | — | Shows a Try again button in the error state and calls this when it is pressed. |
| pattern | ChartPattern | ChartPattern[] | — | One pattern form from the shared pattern library (, , …) for every slice, drawn in its colour on a tint of it, for print and colour-blind reading. A list keeps its first entry; a mark under 20 px on its shorter side stays solid. (one per slice, the pattern donut) wins when both are set. |
| patterns | (ChartPattern | null)[] | — | A fill pattern per slice (null = solid), in the slice colour on a tint of it, e.g. solid, stripes and dots in one indigo donut. A slice too small for a few tiles of its pattern stays solid. Several forms in one chart are an exception to the one-pattern rule, for a donut that tells parts apart without hue. |
| rounded | boolean | false | Rounded slice corners from the bar radius tokens (4 px, up to 8 px on thick rings) with an even 2.5 px gap between the slices. |
| tooltip | boolean | — | |
| width | number | — |
Notes for AI
Give your coding assistant the Markdown reference instead of screenshots.
get_component("pie-chart")The full library index for assistants is at /llms.txt.
Related components
Stacked chart, 12 points from Jan to Dec. Direct from $14.0k to $27.0k, lowest $14.0k, highest $27.0k; Organic from $10.0k to $17.0k, lowest $10.0k, highest $17.0k; Referral from $5.0k to $11.0k, lowest $5.0k, highest $11.0k. Stacked Charts, data table month Direct Organic Referral Jan $14.0k $10.0k $5.0k Feb $18.0k $11.0k $7.0k Mar $16.0k $10.0k $6.0k Apr $20.0k $14.0k $8.0k May $19.0k $13.0k $7.0k Jun $23.0k $15.0k $9.0k Jul $21.0k $14.0k $8.0k Aug $25.0k $16.0k $10.0k Sep $22.0k $15.0k $9.0k Oct $20.0k $13.0k $8.0k Nov $24.0k $16.0k $10.0k Dec $27.0k $17.0k $11.0k Charts13 stylesProStacked ChartStacked chart for the parts of a total: stacked and 100 % columns, stacked areas, diverging Likert bars, Marimekko and gapped rows.Revenue by product line: 12 parts, total $1.8M. Largest: Enterprise $410k, Core $340k, Pro $260k. Revenue by product line, data table label Path Value Share Core Software › Core $340k 18.4% Pro Software › Pro $260k 14.1% Enterprise Software › Enterprise $410k 22.2% Add-ons Software › Add-ons $90k 4.9% Onboarding Services › Onboarding $120k 6.5% Training Services › Training $80k 4.3% Support Services › Support $150k 8.1% Devices Hardware › Devices $180k 9.8% Accessories Hardware › Accessories $60k 3.3% Templates Marketplace › Templates $70k 3.8% Plugins Marketplace › Plugins $55k 3% Themes Marketplace › Themes $30k 1.6% Charts5 stylesProTreemapTreemap for the parts of a hierarchy: squarified, nested with group headers, or as an icicle.Revenue by product line: Software $1.1M, Services $350k, Hardware $240k, Marketplace $155k; total $1.8M. Revenue by product line, data table label Value Software $1.1M Services $350k Hardware $240k Marketplace $155k Core $340k Pro $260k Enterprise $410k Add-ons $90k Onboarding $120k Training $80k Support $150k Devices $180k Accessories $60k Templates $70k Plugins $55k Themes $30k Charts4 stylesProSunburstSunburst for a hierarchy as rings, or as circle packing.