Donut chart
A sweeping donut that shows the hovered slice in the middle, paired with a legend.
- Direct 4,200
- Search 3,100
- Social 1,800
- Email 900
Installation
pnpm add @heyramzi/uiUsage
import { DonutChart, Legend } from "@heyramzi/ui/charts";<DonutChart
data={[{ source: "Direct", visits: 4200, color: "var(--chart-1)" }]}
valueKey="visits"
labelKey="source"
colorKey="color"
centerLabel="Visits"
/>
<Legend items={[{ label: "Direct", value: 4200, color: "var(--chart-1)" }]} showValue />Keyboard and accessibility
- The chart is an image named by centerLabel and the total, like "Revenue: 12,400 total". The slices aren't in the name, so list them in text or a legend.
- With reduced motion on, the slices show without sweeping in.
API reference
datarequiredTData[]valueKeyrequiredkeyof TData & stringlabelKeyrequiredkeyof TData & stringcolorKeykeyof TData & stringheightnumber- Default
240 innerRadiusnumber- Default
60 outerRadiusnumber- Default
100 centerLabelstring- Center label shown when nothing is hovered
formatValue(v: number) => string- Default
(v) => v.toLocaleString() - Format the center value
classstring
| Prop | Type | Default |
|---|---|---|
data required | TData[] | |
valueKey required | keyof TData & string | |
labelKey required | keyof TData & string | |
colorKey | keyof TData & string | |
height | number | 240 |
innerRadius | number | 60 |
outerRadius | number | 100 |
centerLabel Center label shown when nothing is hovered | string | |
formatValue Format the center value | (v: number) => string | (v) => v.toLocaleString() |
class | string |