Donut / Pie chart

Parts of a whole, up to about six slices. The legend is a real list with value and share; hovering a slice or focusing a row shows it in the centre, clicking a row hides it. Donut, pie and half-ring variants.

Recharts PieChart charts/donut-chart.tsxtheme · material · accent · density · font

Organic search 44% (1,284), Paid ads 29.5% (862), Referrals 14.8% (431), Events 6.8% (198), Partners 5% (145).

Leads by source, Q4
CategoryValueShare
Organic search1,28444%
Paid ads86229.5%
Referrals43114.8%
Events1986.8%
Partners1455%

Installation

$ pnpm add @vamos-ui/react

The whole kit as one package — get updates by bumping the version. Add the styles to globals.css: @import "@vamos-ui/react/styles.css";

Usage

import { DonutChart } from "@vamos-ui/react/charts";

<DonutChart title="Leads by source" data={rows} nameKey="source" valueKey="leads"
  config={{ organic: { label: "Organic search" }, paid: { label: "Paid ads" } }} />

All-zero data renders an empty ring in --track with "No data".

The ring itself is not focusable; the legend list is the keyboard path.

Examples

Half ring (HR)

variant="half" with the legend under it.

Full-time 67.7% (168), Part-time 16.5% (41), Contractors 10.9% (27), Interns 4.8% (12).

Contract types
CategoryValueShare
Full-time16867.7%
Part-time4116.5%
Contractors2710.9%
Interns124.8%

Other grouping

Beyond maxSlices the smallest slices merge into a neutral "Other".

Türkiye 40% (18,420), Germany 20.2% (9,310), United States 17.1% (7,860), United Kingdom 9% (4,120), Other 13.7% (6,320).

Visits by country
CategoryValueShare
Türkiye18,42040%
Germany9,31020.2%
United States7,86017.1%
United Kingdom4,1209%
Other6,32013.7%

Custom centre (CMS)

center takes any node; byte values use format: "bytes".

Images 41.2% (41.2 GB), Video 28.7% (28.7 GB), Documents 6.3% (6.3 GB), Free 23.8% (23.8 GB).

Media library storage
CategoryValueShare
Images41.2 GB41.2%
Video28.7 GB28.7%
Documents6.3 GB6.3%
Free23.8 GB23.8%

Pie

variant="pie" — no centre, thin separators.

Mobile 61.1% (7,420), Desktop 34.5% (4,190), Tablet 4.4% (530).

Sessions by device
CategoryValueShare
Mobile7,42061.1%
Desktop4,19034.5%
Tablet5304.4%

API

DonutChart

PropTypeDefault
title / data / config / state / summary / labels
See Chart frame. config is keyed by slice id (the nameKey value).
ChartProps—
nameKey
Row key holding the slice id.
keyof T—
valueKey
Row key holding the value.
keyof T—
variant
Shape.
"donut" | "pie" | "half""donut"
size
120 / 180 / 240 px diameter.
"sm" | "md" | "lg" | number"md"
center
Centre content; the active slice replaces it while hovered or focused.
ReactNode | "total" | "none""total"
centerLabel
Label under the total.
string"Total"
maxSlices
Rest → "Other" (fg-subtle).
number5
legend
Legend list position (side falls under the ring in a narrow container).
"side" | "bottom" | "none""side"
format
Value format. Default: the first config entry's format.
FormatSpec—
activeKey / onActiveChange
Controlled active slice.
string | null—