Skip to content
h v3.13.3
Search the docs
Find a component, section or page.

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/ui

Usage

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

data required TData[]
valueKey required keyof TData & string
labelKey required keyof TData & string
colorKey keyof TData & string
height number
Default 240
innerRadius number
Default 60
outerRadius number
Default 100
centerLabel string
Center label shown when nothing is hovered
formatValue (v: number) => string
Default (v) => v.toLocaleString()
Format the center value
class string
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