nook
Browse the docs

Components

Pie Chart

Native

Shows how a whole splits into a few parts, as a filled disc with a list of the parts beside it.

See the prompt
Visits by browser in November
Visits by browser in November
PartValueShare
Chrome5.1K50%
Safari3.3K32%
Firefox9409%
Edge6106%
Other2703%

Installation

npx nook-ui@latest add pie-chart

Prompt

Paste this into your AI coding assistant. It adds this exact component, the same way the CLI does, and tells the assistant how to use it.

Short. For assistants that can run commands in your project.

Plain text
Add the Nook "Pie Chart" component to this project, exactly as Nook ships it.

Shows how a whole splits into a few parts, as a filled disc with a list of the parts beside it.

Steps
1. Check for `nook.json` in the project root. If it is missing, run `npx nook-ui@latest init` first (React or Next.js with Tailwind CSS v4). It adds the Nook tokens, the theme and `cn()`.
2. Run `npx nook-ui@latest add pie-chart`. It writes `components/ui/pie-chart.tsx` together with everything the component needs. Do not write the component from memory.
3. If you cannot run commands, fetch http://localhost:3000/r/pie-chart.json, write every entry of `files` to the path it names, install the packages in `dependencies`, and repeat for each name in `registryDependencies`.
4. Use it where I ask. Start from this example:

```tsx
import { PieChart } from "@/components/ui/pie-chart";

const DATA = [
  { label: "Chrome", value: 5120 },
  { label: "Safari", value: 3280 },
  { label: "Firefox", value: 940 },
  { label: "Edge", value: 610 },
  { label: "Other", value: 270 },
];

export default function PieChartDefault() {
  return <PieChart className="w-full" title="Visits by browser in November" data={DATA} />;
}
```

API
- `PieChart`: The chart. Takes the same props as DonutChart except the thickness and the center content.
  - `data` (`{ label; value }[]`): Up to five parts. Fold smaller ones into Other.
  - `title` (`string`): What the chart shows.
  - `legend` (`boolean`, default true): Show the list of parts.
  - `formatValue` (`(value: number) => string`): Formats values.

Rules
- Colors, radii, shadows and motion come from Nook tokens and classes such as `bg-primary`, `text-muted-foreground`, `border-border`, `rounded-lg` and `h-control`. Never hard-code them.
- Do not restyle or simplify the file. Change how it looks through `className`, its props and the theme.
- It must keep working with the keyboard, in light and dark mode, and in the sharp, soft and bold styles.
- Accessibility: The same data is in a table for screen readers. Every slice has a title with its value, and the list names every part with its value and share, so color is never the only cue.

Done when the component renders like the example in light and dark mode and the project type-checks.

Usage

import { PieChart } from "@/components/ui/pie-chart";

const DATA = [
  { label: "Chrome", value: 5120 },
  { label: "Safari", value: 3280 },
  { label: "Firefox", value: 940 },
  { label: "Edge", value: 610 },
  { label: "Other", value: 270 },
];

export default function PieChartDefault() {
  return <PieChart className="w-full" title="Visits by browser in November" data={DATA} />;
}

Examples

With currency

Revenue by plan
Revenue by plan
PartValueShare
Team$18,40052%
Business$12,90036%
Solo$4,30012%

Without the list

Where the budget goes: 55% people, 30% tools, 15% travel
Where the budget goes: 55% people, 30% tools, 15% travel
PartValueShare
People5555%
Tools3030%
Travel1515%

Props

PieChart

The chart. Takes the same props as DonutChart except the thickness and the center content.

PropTypeDefaultDescription
data{ label; value }[]–Up to five parts. Fold smaller ones into Other.
titlestring–What the chart shows.
legendbooleantrueShow the list of parts.
formatValue(value: number) => string–Formats values.

Accessibility

The same data is in a table for screen readers. Every slice has a title with its value, and the list names every part with its value and share, so color is never the only cue.

Checked against WCAG 2.1 AA with automated axe tests and keyboard tests on every release.