Proportion · Basic

Pie chart

Each item's share of the whole.

Open in playground
Use when
2 to 4 items that add up to 100%
Avoid when
More than 4 items, or values close to each other (bars are more accurate)

Try it

01

Pie chart

Sales share by device
  • Mobile
  • Desktop
  • Tablet
Pie chartPie chart. 3 items, total 100. Mobile 72%, Desktop 23%, Tablet 5%.72%23%5%
Pie chart data
Mobile72% · 72
Desktop23% · 23
Tablet5% · 5
Only 2 to 4 itemsBasic

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 pie --variant <id>) and the MCP server know the same names.

Values on slices

Sales share by device
  • Mobile
  • Desktop
  • Tablet
Sample data

Names on slices

Sales share by device
  • Mobile
  • Desktop
  • Tablet
Sample data

Only the highlight in color

Sales share by device
  • Mobile
  • Desktop
  • Tablet
Sample data

Code

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

const data = [
  {"device":"Mobile","sales":72},
  {"device":"Desktop","sales":23},
  {"device":"Tablet","sales":5},
];

export function Example() {
  return (
    <ChartCard number="01" title="Pie chart" subtitle="Sales share by device" takeaway="Only 2 to 4 items" level="basic" replay>
      <PieChart
        data={data}
        label="device"
        value="sales"
        highlight="Mobile"
      />
    </ChartCard>
  );
}

Props

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

29 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
colorModeA gray step per item (categorical) or color only the highlight (emphasis)"categorical" | "emphasis"Default "categorical"
sortSort largest firstbooleanDefault false
startAngleStart angle in degrees. 0 is 12 o'clocknumberDefault 0
labelModeWhat slice labels show"percent" | "value" | "label" | "none"Default "percent"
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>