Xzero UI
Pro library

Donut chart

A donut whose arcs morph between datasets, with the active value rolling into the center.

$ pnpm dlx shadcn@4.23.0 add @xzero-ui/donut-chart
Live · keyboard ready

When to use

When not to use

Installation

Register both Xzero UI namespaces in your project's components.json:

{
  "registries": {
    "@xzero-ui": "https://mcp.xzero.co.uk/r/{name}.json",
    "@xzero-ui-pro": "https://mcp.xzero.co.uk/r/pro/{name}.json"
  }
}
npx shadcn@4.23.0 add @xzero-ui/donut-chart

Install xzero-foundation once, and import @/components/xzero/foundation.css in your app root. No Xzero token is used by this snapshot. For sample portraits, photos, fonts, or logos, download https://mcp.xzero.co.uk/install-assets.mjs and run node xzero-install-assets.mjs <receiving-project>.

Usage

import { DonutChart } from "@/components/xzero/donut-chart/donut-chart";

export function TrafficSources() {
  return (
    <DonutChart
      label="Visits by source"
      unit="visits"
      data={[
        { key: "search", label: "Search", value: 4210 },
        { key: "direct", label: "Direct", value: 2380 },
        { key: "social", label: "Social", value: 1190 },
        { key: "email", label: "Email", value: 640 },
        { key: "ads", label: "Ads", value: 120 },
        { key: "other", label: "Referral", value: 90 },
      ]}
    />
  );
}

API reference

DonutChart

A donut chart with a synced legend that shows and hides segments, a rolling center readout, automatic Other grouping, and arcs that morph between datasets.

PropTypeDefaultDescription
data (required)DonutChartDatum[]–Parts: { key, label, value, color? }. Values of zero or less are left out.
label (required)string–What the whole is, such as "Visits by source". Names the chart for assistive technology.
unitstring""Unit after values, such as "visits". Shown under the total at rest.
formatValue(value: number) => stringgrouped numberFormats values in the center, legend, and table.
totalLabelstring"Total"Center label at rest, above the total.
sizenumber208Diameter in pixels. The chart scales down to fit narrower containers.
thicknessnumber24Ring thickness in pixels.
groupBelownumber0.04Parts below this share of the total join Other, when at least two would.
maxSegmentsnumber6The most segments drawn, counting Other. The smallest parts beyond it are grouped.
otherLabelstring"Other"Label of the grouped segment.
activeKeystring | null–Controlled selected segment key. Hover and focus preview other segments without changing it.
defaultActiveKeystring | nullnullSelected segment on first render when uncontrolled.
onActiveChange(key: string | null) => void–Called when a segment is pinned or unpinned by clicking the ring, or a legend row when legendAction is select.
hiddenKeysstring[]–Controlled hidden segment keys. A hidden segment closes and the rest of the ring redistributes.
defaultHiddenKeysstring[][]Hidden segments on first render when uncontrolled.
onHiddenKeysChange(keys: string[]) => void–Called when a legend row shows or hides its segment.
legendAction"toggle" | "select""toggle"What clicking a legend row does: show or hide its segment, or pin it as the selected segment.
legendbooleantrueThe synced legend beside or below the ring.
emptyLabelstring"No data yet"Center text when the total is zero.
refRef<HTMLElement>–The figure element.
classNamestring–Class on the figure.

Keyboard interactions

KeysAction
ArrowDown / ArrowRightMoves to the next legend row, looping at the end.
ArrowUp / ArrowLeftMoves to the previous legend row.
Home / EndJumps to the first or last row.
Enter / SpaceShows or hides the focused segment; with legendAction select, pins or unpins it.
EscapeClears the pinned segment.
Arrow keys on the ringWithout a legend the ring takes focus: arrows walk the segments, Enter pins one, and each is announced.

Accessibility

Motion

Responsive behavior

Performance

Notes for AI

Also in charts

Guidance for AI tools

Donut chart: A donut whose arcs morph between datasets, with the active value rolling into the center. Follow the declared prop types and do not invent props. Keep keyboard access, reduced motion support, and both light and dark themes intact when adapting it.

Full library index: https://ui.xzero.co.uk/llms.txt

Browse all components