nook
Browse the docs

Components

Donut Chart

Native

Shows how a whole splits into a few parts, with every part and its share listed beside the ring.

See the prompt
Spending in November by category
Spent$2,225
Spending in November by category
PartValueShare
Rent$1,20054%
Food$54024%
Transport$2109%
Fun$1808%
Other$954%

Installation

npx nook-ui@latest add donut-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 "Donut Chart" component to this project, exactly as Nook ships it.

Shows how a whole splits into a few parts, with every part and its share listed beside the ring.

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 donut-chart`. It writes `components/ui/donut-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/donut-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 { DonutChart } from "@/components/ui/donut-chart";

const DATA = [
  { label: "Rent", value: 1200 },
  { label: "Food", value: 540 },
  { label: "Transport", value: 210 },
  { label: "Fun", value: 180 },
  { label: "Other", value: 95 },
];

export default function DonutChartDefault() {
  return (
    <DonutChart className="w-full" title="Spending in November by category" data={DATA} formatValue={(v) => `$${v.toLocaleString("en")}`}>
      <span className="text-xs text-muted-foreground">Spent</span>
      <span className="text-xl font-semibold tracking-tight tabular-nums">$2,225</span>
    </DonutChart>
  );
}
```

API
- `DonutChart`: The ring and its list. Children sit in the middle.
  - `data` (`{ label, value }[]`): Up to five parts.
  - `title` (`string`): What the chart shows.
  - `thickness` (`number`, default 6): Ring thickness on a 40 unit wide drawing.
  - `formatValue` (`(value: number) => string`): Formats the 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: A hidden table carries the same data for screen readers, and text is never colored by its series. Values are listed next to the ring, so nothing depends on hovering.

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

Usage

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

const DATA = [
  { label: "Rent", value: 1200 },
  { label: "Food", value: 540 },
  { label: "Transport", value: 210 },
  { label: "Fun", value: 180 },
  { label: "Other", value: 95 },
];

export default function DonutChartDefault() {
  return (
    <DonutChart className="w-full" title="Spending in November by category" data={DATA} formatValue={(v) => `$${v.toLocaleString("en")}`}>
      <span className="text-xs text-muted-foreground">Spent</span>
      <span className="text-xl font-semibold tracking-tight tabular-nums">$2,225</span>
    </DonutChart>
  );
}

Examples

Thick ring

Support tickets by type
Tickets489
Support tickets by type
PartValueShare
Billing12826%
Bugs9620%
How to21143%
Feature asks5411%

One number, no legend

Storage used: 72 of 100 GB
72%of 100 GB
Storage used: 72 of 100 GB
PartValueShare
Used7272%
Free2828%

Props

DonutChart

The ring and its list. Children sit in the middle.

PropTypeDefaultDescription
data{ label, value }[]–Up to five parts.
titlestring–What the chart shows.
thicknessnumber6Ring thickness on a 40 unit wide drawing.
formatValue(value: number) => string–Formats the values.

Accessibility

A hidden table carries the same data for screen readers, and text is never colored by its series. Values are listed next to the ring, so nothing depends on hovering.

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