Components · Data Display
Donut Chart
BetaAdded v3.2.0
Parts of a whole, with an optional total in the hole. Keep it to six slices or fewer.
import { DonutChart } from '@nexub/react';Playground
Props
size
| Pro | 540 | 45% |
|---|---|---|
| Team | 310 | 26% |
| Starter | 220 | 18% |
| Free | 130 | 11% |
<DonutChart data={plans} center={…} title="Customers by plan" />Examples
With total
Other, legend values and links
States
Customers by plan Pro 540 45% Team 310 26% Starter 220 18% Free 130 11% defaultloadingCustomers by plan Pro 540 45% Team 310 26% Starter 220 18% Free 130 11% size="sm"Customers by plan Pro 540 45% Team 310 26% Starter 220 18% Free 130 11% size="md"Customers by plan Pro 540 45% Team 310 26% Starter 220 18% Free 130 11% size="lg"
Props
| Prop | Type | Default | Description |
|---|---|---|---|
| titlerequired | string | — | Accessible name of the chart. |
| datarequired | DonutDatum[] | — | One entry per slice. |
| center | React.ReactNode | — | Content in the hole, such as the total. |
| valueFormat | ((value: number) => string) | defaultFormat | Formats the hover text and the data table. |
| legend | boolean | true | Show the legend beside the donut. |
| maxSlices | number | — | 11.3: group the smallest slices into one "Other". |
| otherLabel | string | 'Other' | 11.3: group the smallest slices into one "Other". |
| legendValues | boolean | false | 11.3: value and share on each legend row. |
| data[].href | string | — | 11.3: makes the slice's legend row a link. |
| data[].color | 1–8 | 'good' | 'warning' | 'danger' | 'neutral' | — | 11.3: a palette colour or a tone. |
| size | 'sm' | 'md' | 'lg' | 'md' | 11.3: diameter. |
| tableView | string | boolean | — | 11.3: a visible "Show as table" disclosure. |
| emptyState | React.ReactNode | — | Shown when there is no data. Defaults to the "no data" message. |
| errorState | React.ReactNode | — | Shown in place of the data when a load failed, for example an ErrorState with a retry action. Wins over loading and empty. |
| interactive | boolean | — | A crosshair and tooltip that follow the pointer, and arrow-key navigation between points. |
| loading | boolean | — | Shows a skeleton in place of the data and sets aria-busy. |
| onPointClick | ((point: ChartPoint<DonutDatum>) => void) | — | Click, tap, or Enter/Space on a point. Turns interactive on unless it is set to false. |
Accessibility
Screen reader
The chart is a `figure` named by `title`. The drawing is hidden from assistive tech; a visually hidden table carries every value.
Colour is never the only cue: the legend and table name each series. Past six series, label directly or group the rest as "Other".
On iOS & Android
Web only
Donut Chart has no @nexub/react-native twin. On phones, follow the platform pattern instead, or compose it from the native components listed on the React Native page.