DonutChart

Donut and pie charts for displaying proportional data with interactive hover states and optional center content.

Playground

Experiment with different settings:

11.5K
Total
Direct39.1%
Organic27.8%
Referral15.7%
Social10.4%
Email7.0%

Props

Midnight
220
0.6
OffOn
2
Code
<DonutChart
  data={data}
  theme="midnight"
  size={220}
  innerRadius={0.6}
  showLegend
  legendPosition="right"
  padAngle={2}
/>

With Center Content

11.5K
Total
Direct39.1%
Organic27.8%
Referral15.7%
Social10.4%
Email7.0%
tsx
<DonutChart
  data={data}
  dataKey="visits"
  labelKey="source"
  theme="midnight"
  centerContent={
    <div>
      <div className="text-2xl font-bold">11.5K</div>
      <div className="text-sm text-muted">Total</div>
    </div>
  }
/>

Pie Chart

Set innerRadius to 0 for a traditional pie chart:

Direct39.1%
Organic27.8%
Referral15.7%
Social10.4%
Email7.0%

Props

PropTypeDefaultDescription
data*T[]-Data array
dataKey*keyof T-Key for segment values
labelKey*keyof T-Key for segment labels
sizenumber200Chart size (width and height)
theme*ThemeName-Theme name
innerRadiusnumber0.6Inner radius ratio (0 = pie)
showLegendbooleantrueShow legend
legendPosition"right" | "bottom""right"Legend position
centerContentReactNode-Content to display in center
padAnglenumber2Pad angle between segments