PieChart

Pie or donut chart with hover segments and optional legend.

Category: chart · WCAG 2.1-AA · chart, pie, donut, data-viz

Variants

Props

PropTypeDefaultDescription
dataPieChartDatum[]Array of { id, label, value, color? } datums. Optional per-datum `color` (any CSS color) overrides the positional palette for that slice.
titlestringTitle text for the component.
descriptionstringSupporting description text.
donutbooleanRender as donut chart
widthnumberFixed SVG width in px. ⚠ **Omit for a responsive chart** — the chart fills and tracks its container via a ResizeObserver; there is no correct pixel number in a responsive grid. A fixed width is clamped to the container (max-inline-size: 100%) so it can never overflow its card, but it also stops the chart growing. `useChartSize` is NOT needed for this — charts call it internally.
heightnumber300SVG height in px. Unlike `width`, height does NOT track the container — this is the knob you set to change the chart's aspect.
sizenumberSquare shorthand: sets width === height. Explicit width/height win.
thicknessnumberRing width in px (donut only); defaults to 0.4 × radius.
innerRadiusnumberInner radius in px (donut only); takes precedence over thickness; clamped to [0, outerRadius).
centerValuestringCenter value text rendered in the donut hole (donut only).
centerLabelstringCenter label text rendered below the value (donut only).
centerSlotReactNodeArbitrary content for the donut hole; takes precedence over centerValue/centerLabel.
emptyLabelstringVisible placeholder text when data is empty. Defaults to the i18n "No data".
tooltipFormat(p: ChartPoint) => stringCustom tooltip formatter. Defaults to "value (pct%)" in the slice color.
legendbooleanWhether to show the legend.
classNamestringAdditional CSS class names merged onto the root element.
plainbooleanfalseMarks only — no axes, grid lines, or legend. For micro/inline charts.
labelsboolean | { format?: (v: number) => string; position?: string }Print each value as a label on the mark (collision-aware, decorative/aria-hidden).
onSelect(point: ChartPoint) => voidFired when a point is clicked or activated (Enter/Space) — for drill-down.

Design tokens

When to use

When not to use

Examples

Basic pie chart

import { PieChart } from '@cascivo/charts'

<PieChart data={[{label:'A',value:60},{label:'B',value:40}]} title="Market share" />

Donut with center total and custom thickness

import { PieChart } from '@cascivo/charts'

<PieChart
  donut
  size={220}
  thickness={28}
  centerValue="142"
  centerLabel="Total tasks"
  data={[
    { id: 'done', label: 'Done', value: 92, color: 'var(--cascivo-color-success)' },
    { id: 'wip', label: 'In progress', value: 34, color: 'var(--cascivo-color-warning)' },
    { id: 'blocked', label: 'Blocked', value: 16, color: 'var(--cascivo-color-destructive)' },
  ]}
  title="Task status"
/>

Percentage tooltip + empty state

import { PieChart } from '@cascivo/charts'

// Default tooltip shows "value (pct%)" in the slice color; pass tooltipFormat to override.
<PieChart data={[{id:'a',label:'A',value:60},{id:'b',label:'B',value:40}]} title="Share" />

// Empty data renders a visible "No data" placeholder (override via emptyLabel).
<PieChart data={[]} title="Share" emptyLabel="Nothing tracked yet" />

Related components

← Back to docs