Donut chart

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

npx shadcn@latest add @silicon-ui/donut-chart
datanew
Loading…

Installation

With the shadcn CLI

npx shadcn@latest add @silicon-ui/donut-chart

Manually

  1. Install the dependencies.

    npm install motion
  2. Copy these files into your project. Shared files are skipped if you already have them.

    • components/silicon-ui/donut-chart/donut-chart.tsx
    • components/silicon-ui/donut-chart/donut-chart.module.css
  3. Install the foundation once per app for the design and motion tokens: npx shadcn@latest add @silicon-ui/silicon-foundation

Usage

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

API reference

PropTypeDefault
data*DonutChartDatum[]—
label*

What the whole is, such as "Visits by source". Names the chart for assistive technology.

string—
unit

Unit after values, such as "visits".

string""
formatValue(value: number) => stringvalue => grouped.format(value)
totalLabel

Center label at rest, above the total.

string"Total"
size

Diameter in pixels. The chart scales down to fit narrower containers.

number208
thickness

Ring thickness in pixels.

number24
groupBelow

Segments below this share of the total join "Other".

number.04
maxSegments

The most segments drawn, counting "Other". The smallest parts beyond it are grouped.

number6
otherLabelstring"Other"
activeKey

Controlled selected segment key. Hover and focus preview other segments without changing it.

string | null—
defaultActiveKeystring | nullnull
onActiveChange(key: string | null) => void—
hiddenKeys

Controlled hidden segment keys. A hidden segment closes and the rest of the ring redistributes.

string[]—
defaultHiddenKeysstring[]—
onHiddenKeysChange(keys: string[]) => void—
legendAction

What clicking a legend row does: show or hide its segment, or pin it as the selected segment.

"toggle" | "select""toggle"
legend

The synced legend beside or below the ring.

booleantrue
emptyLabelstring"No data yet"
refRef<HTMLElement>—
classNamestring—

Dependencies

npm
motion
Registry
silicon-motion-tokens