Pie chart
Show a compact part to whole comparison when the differences are easy to see.
- Deep work
- Meetings
- Admin
- Value
- 52%
View data table 3 rows
| Data point | Value |
|---|---|
| Deep work | 52% |
| Meetings | 27% |
| Admin | 21% |
Installation
bunx --bun shadcn@latest add https://apple-ui-eduardo.vercel.app/r/pie-chart.jsonThe 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
"use client";
import { PieChart } from "@eduardoul/apple-ui";
const data = [
{ label: "Deep work", value: 52 },
{ label: "Meetings", value: 27 },
{ label: "Admin", value: 21 },
];
export function Example() {
return (
<PieChart
title="Time allocation"
description="Synthetic share of tracked time"
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
| Property | Type | Default |
|---|---|---|
| data | ChartDatum[] | required |
| valueKey | string | value |
| labelKey | string | label |
| title | string | required |
| description | string | undefined |
| height | number | component default |
| loading | boolean | false |
| error | string | undefined |
| emptyMessage | string | No data to display. |
| showTable | boolean | true |
| compact | boolean | false |
| valueFormatter | (value: number) => string | localized number |
| className | string | undefined |
| style | React.CSSProperties | undefined |
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 pie only when every value is part of the same whole.
- Keep the segment count low and avoid slices whose sizes are difficult to distinguish.
- Never pass negative or nonfinite values. The chart reports invalid proportion data instead of changing it silently.
- An all zero dataset has no proportions, so the chart presents an explanatory empty state.
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.