Proportion · Basic

Donut chart

A share chart with the total in the center.

Open in playground
Use when
The total matters as much as the shares
Avoid when
More than 6 items

Try it

02

Donut chart

Share by conversion type
Donut chartDonut chart. 4 items, total 1,240. Purchase 58%, Sign-up 21%, Inquiry 13%, Call 8%.1,240ConversionsPurchase58%Sign-up21%Inquiry13%Call8%
Donut chart data
Purchase58% · 719
Sign-up21% · 260
Inquiry13% · 161
Call8% · 100
Total in the centerBasic

Hover over the chart, or Tab in and use the arrow keys to move between items. The numbers are sample data.

Variants

Named looks for this chart. Each one is the example above with a few options or fields changed. The CLI (ztd-charts example donut --variant <id>) and the MCP server know the same names.

Thin ring

Share by conversion type
Sample data

Legend on the right

Share by conversion type
Sample data

Largest first

Share by conversion type
Sample data

Code

DonutChart.tsx
import { ChartCard, DonutChart } from "ztd-charts";

const data = [
  {"type":"Purchase","count":719},
  {"type":"Sign-up","count":260},
  {"type":"Inquiry","count":161},
  {"type":"Call","count":100},
];

export function Example() {
  return (
    <ChartCard number="02" title="Donut chart" subtitle="Share by conversion type" takeaway="Total in the center" level="basic" replay>
      <DonutChart
        data={data}
        label="type"
        value="count"
        centerLabel="Conversions"
      />
    </ChartCard>
  );
}

Props

<DonutChart> takes these props. Rows marked Common work the same on every chart.

30 props

Prop
dataRequiredAn array of objects. Pass CSV, REST or database rows as they areobject[]
labelRequiredItem name fieldstring | (d, i) => string
valueRequiredValue fieldstring | (d, i) => number
innerRadiusInner radius rationumberDefault 0.62
centerValueNumber in the center: "total" | "highlight" | a number | null (none)anyDefault "total"
centerLabelCaption under the center numberstring
legendLegend position"auto" | "right" | "bottom" | "none"Default "auto"
sortSort largest firstbooleanDefault false
otherKeep the n largest slices and group the rest into one "Other" slice. The Other slice is never highlightednumber
heightCommonHeight in px. Without it, each chart picks a default that fits its widthnumber
widthCommonFixed width in px. Without it, the chart fits its parentnumber
highlightCommonItem to highlight. An index, a name, an array, or "max" | "min" | "first" | "last" | "none"number | string | (number|string)[] | "max" …
formatCommonValue format. "number" | "integer" | "percent" (values are already percents: 42 → "42%") | "ratio" (0.42 → "42%") | "compact" | "currency" (KRW for Korean locales, otherwise USD; for another currency pass Intl options with currency) | "decimal" or Intl.NumberFormat options"number" | "percent" | "compact" | …
unitCommonUnit appended to values. For example "%" or "ms"string
localeCommonLocale for numbers, dates and the text a chart writes itself (tooltips, screen reader sentences). "ko" or "ko-*" switches to Korean. Falls back to the ThemeProvider localestringDefault "en-US"
animateCommonEntry and update animationbooleanDefault true
durationCommonAnimation length (ms)number
easingCommonMotion curve"spring" | "easeOut" | "easeInOut" | "linear"Default "spring"
staggerCommonDelay between items as they enter (ms)number
reducedMotionCommon"auto" follows the OS setting. true always turns motion offanyDefault "auto"
animateOnViewCommonPlay when the chart scrolls into viewbooleanDefault true
showLabelsCommonLabels drawn on the chart (values and names)booleanDefault true
tooltipCommonShow tooltips. { template: "{label} · {value} · owner {owner}" } writes them: {label}, {value}, {series} or any other column of the row. \n starts a new line, and a line with an empty value is left outtooltipDefault true
syncIdCommonCharts with the same syncId show the hovered x together (line, area, bar, candlestick). <ChartGrid sync> sets one for every chart inside itstring
ariaLabelCommonName for screen readersstring
descriptionCommonDescription for screen readers. Built from the data when omittedstring
onHoverCommonRuns when hover or keyboard focus moves to another item(e: ChartEvent | null) => void
onClickCommonRuns on click, Enter or Space(e: ChartEvent) => void
replayKeyCommonReplays the entry animation when it changesstring | number
themeCommonChanges theme tokens for this chart onlyPartial<ChartTheme>