Interactive example
Project statusSynthetic project shares
  • Planned
  • In progress
  • Complete
Use arrow keys to select a data point. Home selects the first point and End selects the last. Escape closes the value tooltip.
Planned
Value
46%
View data table 3 rows
Project status
Data pointValue
Planned46%
In progress31%
Complete23%

Installation

terminal
bunx --bun shadcn@latest add https://apple-ui-eduardo.vercel.app/r/donut-chart.json

The registry includes the shared styles and dependencies. Import @/components/apple-ui/styles.css in your root layout once. For the package route, use the installation guide.

Usage

tsx
"use client";

import { DonutChart } from "@eduardoul/apple-ui";

const data = [
  { label: "Planned", value: 46 },
  { label: "In progress", value: 31 },
  { label: "Complete", value: 23 },
];

export function Example() {
  return (
    <DonutChart
      title="Project status"
      description="Synthetic project shares"
      data={data}
      valueFormatter={(value) => value + "%"}
    />
  );
}

Package imports use @eduardoul/apple-ui. Registry imports use @/components/apple-ui. Add "use client" to files that use state or event handlers.

API reference

PropertyTypeDefault
dataChartDatum[]required
valueKeystringvalue
labelKeystringlabel
titlestringrequired
descriptionstringundefined
heightnumbercomponent default
loadingbooleanfalse
errorstringundefined
emptyMessagestringNo data to display.
showTablebooleantrue
compactbooleanfalse
valueFormatter(value: number) => stringlocalized number
classNamestringundefined
styleReact.CSSPropertiesundefined

Use className and style to customize the component. The package includes full TypeScript definitions for its supported element properties and refs.

Design guidance

  • Use a donut for a few nonnegative parts that add to one meaningful whole.
  • Keep labels visible through a legend or direct annotation. Color alone cannot identify a segment.
  • Use bars when the segments are close in size or when precise comparison matters.
  • An all zero dataset has no proportions, so the chart presents an explanatory empty state.
Read Apple’s guidance

Accessibility

Give the chart a descriptive title and explain its units. Select a data point to read its values, or open the data table for the full dataset. Labels and values accompany color, and the chart adapts to reduced motion and appearance preferences. Test long labels, touch input and keyboard navigation with your own data.

Library styles support reduced motion, reduced transparency, increased contrast and forced colors. Read the accessibility foundation for the checks your application still needs.