Donut chart
A ring of parts of a whole with the total or active share displayed in the center.
import { DonutChart } from '@uthereal/ui/donut-chart'Donut chart playground
Visits by source. Visits 40,610. Search, 16,840, 41%. Direct, 8,120, 20%. Newsletter, 5,260, 13%. Referrals, 6,430, 16%. Social, 2,910, 7%. Other, 1,050, 3%. Includes Podcasts, Partners.
| Segment | Value | Share |
|---|---|---|
| Search | 16,840 | 41% |
| Direct | 8,120 | 20% |
| Newsletter | 5,260 | 13% |
| Referrals | 6,430 | 16% |
| Social | 2,910 | 7% |
| Podcasts (Other) | 640 | 2% |
| Partners (Other) | 410 | 1% |
Overview
A donut chart displays parts of one whole as clockwise 24 px ring segments separated by 3 px surface gaps. The center displays the visible total at rest, or the label, value, and share of the hovered, focused, or pinned segment. Legend rows list each part with its value and share. They sit beside the ring at 460 px or wider, and below it on narrower containers. A native data table lists every visible part and share.
Use a donut chart for six or fewer parts with clearly distinct shares. For close comparisons or grouped series, use a bar chart. For shares that read better as countable units, use a waffle chart.
Usage
import { DonutChart } from '@uthereal/ui/donut-chart'
export function Traffic() {
return (
<DonutChart
title="Traffic by source"
parts={[
{ id: 'direct', label: 'Direct', value: 42 },
{ id: 'search', label: 'Search', value: 31 },
{ id: 'social', label: 'Social', value: 17 },
]}
/>
)
}All part values must be zero or more, with at least one positive value. Colors follow the configured order of parts so hiding or updating parts never shifts remaining colors. Set color (hex, rgb, hsl, oklch, or var(--token)) on a part to override its palette slot.
Examples
Currency format, hidden segments, and data table
Combine valueFormat for currency readouts, defaultHiddenParts to start with a segment toggled off, a custom totalLabel, and tableToggle to reveal the native data table on demand. Parts below groupBelow (4% by default) or beyond maxParts fold automatically into otherLabel as shown in the playground above.
Quarterly cloud spend. Spend $79,900. Compute, $42,800, 54%. Storage, $19,400, 24%. Network, $11,200, 14%. Support, $6,500, 8%.
| Segment | Value | Share |
|---|---|---|
| Compute | $42,800 | 54% |
| Storage | $19,400 | 24% |
| Network | $11,200 | 14% |
| Support | $6,500 | 8% |
Behavior
Legend rows either hide and show parts (legendAction: 'toggle', default) or pin one (legendAction: 'select'). Totals and shares recalculate across visible parts, and the last visible part cannot be hidden. Hidden parts remain in the legend with a hollow dot. Hovering or focusing a legend row previews its segment. Set legend: false to omit the legend, and unit to append a unit label under the total and beside values.
Pointing at a segment lifts it 4 px outward along its bisector, thickens it by 2 px, dims other segments, and updates the center readout. Clicking a segment pins it; clicking again unpins it. When no visible part has a positive value, the ring displays its empty track and emptyLabel.
API reference
These serializable arguments and defaults come directly from the component schema.
| Argument | Type / default | Description |
|---|---|---|
title | stringDefault: "Donut chart" | Figure title. It names the chart for assistive technology and captions the data table. |
description | string— | One or two sentences on what the chart shows, below the title; omit it when the title says enough. |
tableToggle | booleanDefault: false | Show a button that reveals the data table. The table is always available to assistive technology. |
tableLabel | stringDefault: "Data table" | Name of the data table button. |
pointLabel | stringDefault: "{label}, {value}, {share}" | Names a part in the legend, keyboard announcements and the summary: {label}, {value} (with the unit) and {share} of the visible total ("Search, 16,840, 41%"). The folded part adds the includesLabel sentence. |
valueFormat | NumberFormat— | How values appear in the tooltip, table and axis: decimal, percent or currency, with fraction digits. Axis ticks are compacted (12.9K). |
locale | string— | BCP 47 locale for numbers and dates. Omit it to inherit the application locale (en-US by default). |
parts | ChartPart[]Default: [{"id":"direct","label":"Direct","value":42},{"id":"search","label":"Search","value":31},{"id":"social","label":"Social","value":17},{"id":"email","label":"Email","value":10}] | The parts of the whole in display order, each with an id, a label and a value of zero or more; at least one is greater than zero. Colors follow this order and never move when a part is hidden. |
maxParts | integerDefault: 6 | Parts shown before the rest fold into one "Other" part in gray (2–8). The data table always lists every part. |
groupBelow | numberDefault: 0.04 | Parts below this share of the whole (0–0.5; 0.04 is 4%) fold into "Other", but only when two or more would fold. |
otherLabel | stringDefault: "Other" | Name of the folded part. |
categoryLabel | stringDefault: "Segment" | Header of the part column in the data table ("Segment"). |
valueLabel | stringDefault: "Value" | Header of the value column in the data table. |
shareLabel | stringDefault: "Share" | Header of the share column in the data table (each part’s share of the whole). |
legendLabel | stringDefault: "{title}, segments. Press a segment to show or hide it" | Accessible name of the legend when rows toggle; {title} is the chart title. |
unit | string— | Unit after every value in names, announcements and the table, such as "visits"; shown under the total in the center. |
legend | booleanDefault: true | Show the legend beside the ring (or below it in a narrow container). Without it the ring itself is the keyboard stop. |
legendAction | toggle | selectDefault: "toggle" | What pressing a legend row does: toggle shows or hides its part (the last shown part stays), select pins it as a ring click does. |
legendSelectLabel | stringDefault: "{title}, segments" | Accessible name of the legend when rows pin; {title} is the chart title. |
ringLabel | stringDefault: "{title}. Use the arrow keys to read each segment." | Accessible name of the ring when there is no legend; {title} is the chart title. |
hiddenLabel | stringDefault: "{label}, hidden" | Name of a hidden part in the legend; {label}. |
includesLabel | stringDefault: "Includes {members}" | Sentence after the folded part in names and the summary; {members} lists what it holds. |
moreMembersLabel | stringDefault: "{members} and {count} more" | Legend line under a folded part of more than two: {members} (the first two) and {count}. |
shownAnnouncement | stringDefault: "{label} shown. {totalLabel} {total}." | Announced when a legend row shows its part: {label}, {totalLabel} and the new {total}. |
hiddenAnnouncement | stringDefault: "{label} hidden. {totalLabel} {total}." | Announced when a legend row hides its part: {label}, {totalLabel} and the new {total}. |
defaultHiddenParts | string[]Default: [] | Parts hidden at first ("other" for the folded part). Later edits do not reset an existing instance; use hiddenParts and onHiddenPartsChange to control them. |
totalLabel | stringDefault: "Total" | Names the total in the center of the ring. |
shareOfTotalLabel | stringDefault: "{share} of {total}" | The center line under an active part: {share} of the parts shown and {total}, the total label in lower case ("41% of visits"). |
emptyLabel | stringDefault: "No data yet" | Center text when nothing shown has a value; the ring shows its empty track. |
defaultActive | string— | The part pinned at first ("other" for the folded part). A click or Enter pins a part, a second press or Escape unpins it; the center keeps reading it while nothing else is hovered. |
size | sm | md | lgDefault: "md" | Ring width of 168, 208 or 248 pixels. |
recipe | studio | softDefault: "studio" | Visual treatment. Both recipes use the same interaction behavior. |
theme | DonutChartTheme— | Color mode, accent, and tokens, including size, valueSize and the chart palette. See Theming. |
motion | none | subtle | expressiveDefault: "subtle" | Draw-in and data change animation preset. System reduced-motion preferences take precedence. |
motionOptions | ChartMotionOptions— | draw (the ring sweeping in clockwise from the top when the chart scrolls into view) and morph (segments springing to new data; Arc's .5 s settle spring when omitted): a tween with a duration (ms) or a spring. |
dir | ltr | rtl— | Reading direction of the text; the ring always runs clockwise from the top. Omit it to inherit the page direction. |
React integration
| Prop | Purpose |
|---|---|
active | Controlled pinned part ID, or null for none |
onActiveChange | Fires with the pinned part ID (or null) on pin or unpin, in both modes |
hiddenParts | Controlled list of hidden part IDs ("other" targets the folded segment) |
onHiddenPartsChange | Fires with the updated hidden part IDs when the legend toggles, in both modes |
preset | Application defaults, overridden by explicit instance props |
tokens | CSS variables applied after the typed theme |
ref | Ref forwarded to the root <figure> |
className, style | Applied to the root <figure> |
| Native attributes | id, data-*, and remaining <figure> attributes forwarded to the root |
Keyboard & accessibility
| Key | Interaction |
|---|---|
Tab | Move across legend buttons (or focus the ring when legend: false) |
ArrowUp, ArrowDown | Move to the previous or next part, wrapping |
ArrowLeft, ArrowRight | Move to the previous or next part, wrapping |
Home, End | Jump to the first or last part |
Enter, Space | Toggle visibility or pin the focused part (legendAction or ring focus mode) |
Escape | Clear the pinned part and active preview |
The chart renders a <figure> named by title. aria-details points to a data table listing every visible part (including individual folded members) and its share of the visible total, while a visually hidden summary announces the total and parts. The SVG ring is hidden from assistive technology.
With a legend, each row button is named by pointLabel, and visibility toggles announce the updated total via shownAnnouncement and hiddenAnnouncement. Without a legend, the ring forms one tab stop named by ringLabel and announces each focused segment politely. Under forced-colors, system colors apply.
Motion and theming
When 35% of the chart enters the viewport, segments sweep in clockwise from 12 o'clock on a reveal spring; server-rendered markup is final. Data updates animate on a 500 ms settle spring (motionOptions.morph): new parts open from their start angle and removed parts close cleanly. Hover and focus lift segments on a snappy spring, the center readout rolls between parts like a drum, and totals and shares count to new numbers. motionOptions.draw and motionOptions.morph accept a tween with duration (ms) or a spring. motion="none" and prefers-reduced-motion: reduce disable motion.
theme accepts a mode, an accent, and semantic tokens including size, valueSize, and the chart palette. An application-wide UtherealProvider supplies defaults.
Composition
In an agent composition, DonutChart is a leaf with no actions. Both the pinned part and hidden parts are host state stored at /components/instance-<id>/active (from defaultActive) and /components/instance-<id>/hiddenParts (from defaultHiddenParts). The host updates parts through composition updates. See Building with agents.
{
"type": "DonutChart",
"props": {
"title": "Spend by category",
"parts": [
{ "id": "cloud", "label": "Cloud", "value": 5400 },
{ "id": "tools", "label": "Tools", "value": 2100 }
]
},
"children": []
}