Donut chart

Donut or pie with Other grouping, honest exclusions, labels inside or outside and a centre readout. Same props on both engines.

Install

Pick one engine. Both builds take the same props, so switching later changes only the import path.

Recharts

npx shadcn@latest add https://beautifulcharts.dev/r/instrument-donut-chart-recharts.json

import { DonutChart } from "@/components/beautiful-charts/themes/instrument/recharts/donut-chart";
npm dependencies: recharts@^3.10.1

Apache ECharts

npx shadcn@latest add https://beautifulcharts.dev/r/instrument-donut-chart-echarts.json

import { DonutChart } from "@/components/beautiful-charts/themes/instrument/echarts/donut-chart";
npm dependencies: echarts@^6.1.0

Example

A complete client module. Paste it into your app after installing the Recharts build; for ECharts, change recharts to echarts in the import. To pick options visually and copy the matching code, use the Customizer.

"use client";

import { DonutChart } from "@/components/beautiful-charts/themes/instrument/recharts/donut-chart";

const data = [
  { channel: "Organic", visits: 4120 },
  { channel: "Referral", visits: 1860 },
  { channel: "Paid search", visits: 1340 },
  { channel: "Social", visits: 720 },
  { channel: "Email", visits: 410 },
];

// Segments under 6% are grouped into one "Other" segment; its tooltip lists every member.
export function TrafficSources() {
  return (
    <DonutChart
      data={data}
      nameKey="channel"
      valueKey="visits"
      title="Traffic by source"
      groupBelow={0.06}
      center={{ label: "visits" }}
    />
  );
}

Donut chart props

Generated from DonutChartProps in the installed source, so this table and your editor's hints always agree. * marks a required prop.

Donut chart props
PropTypeDescription
nameKey*keyof TDatum & stringThe field that names each segment, e.g. "channel".
valueKey*keyof TDatum & stringThe field that holds each segment's value, e.g. "revenue".
innerRadiusnumberHole size as a share of the radius, 0–0.9. 0 draws a pie.
padAnglenumberGap between segments, in degrees.
cornerRadiusnumberCorner radius of each segment, in px.
startAnglenumberWhere the ring starts and ends, in degrees clockwise from 12 o'clock. A half ring is -90 to 90.
endAnglenumberWhere the ring ends, in degrees clockwise from 12 o'clock.
groupBelownumberGroup segments smaller than this share (0–1) into one "Other" segment. Members stay in the table and tooltip.
maxSegmentsnumberKeep at most this many segments; the rest go into "Other".
otherLabelstringName of the grouped segment. Defaults to "Other".
labels"none" | "inside" | "outside"Segment labels: none, inside the ring, or outside with leader lines.
labelContent"value" | "share" | "both"What labels and the legend show: the value, the share, or both.
centerfalse | { label?: string }The centre readout. Defaults to the shown total, or the selected segment. false leaves the hole empty.

Recharts build only

Native Recharts children render inside the chart with your original rows, so ReferenceArea, Label or a custom Customized layer work as they do in any Recharts chart.

Recharts build props
PropTypeDescription
childrenReactNodeRecharts children render inside the same PieChart, which receives your original rows: add a native <Pie> ring, a <Label> or anything Recharts accepts. A full ring is centred, so cx/cy "50%" line up with ours.

Apache ECharts build only

Escape hatches into the engine. Your option is deep-merged over the generated one, so you can change one nested setting without replacing a whole section.

Apache ECharts build props
PropTypeDescription
rendererEChartsRenderer"canvas" (default) or "svg".
optionOptionOverrideDeep-merged over the generated option, or a function (generated) => option. The ring is one custom series (id "segments", one data item per segment, id = the segment's name). A full ring is centred, so a native pie series with center ["50%", "50%"] lines up with ours. Register extra modules with registerEChartsModules.

Series config

One entry per series key in config. shadcn's ChartConfig entries work as they are. Give a series at most one of color, theme or colors; TypeScript rejects more than one. This table lists only the options this chart reads.

Donut chart series config
PropTypeDescription
labelReactNodeName shown in the legend, tooltip and table. Defaults to the key, humanised.
ariaLabelstringPlain text for tables, summaries and announcements when label is not a string.
iconComponentType<{ className?: string }>An icon component (e.g. from lucide-react) shown in place of the swatch in the legend and tooltip.
format(value: number) => stringFormats this series' values everywhere: tooltip, legend, table, readout.
colorColorValueOne colour: any CSS colour or var(--chart-1), or { light, dark }.
themenevershadcn's per-theme colours, { light, dark }.
colorsneverGradient stops from base to value end, per theme. The last stop is the series' single colour.

Events

Every callback, and the payload types it receives. Indexes always point into the data you passed, even when a brush or grouping shows a subset.

Donut chart events
PropTypeDescription
onSelectedChange(selection: Selection<TDatum> | null) => voidCalled when a row is selected or cleared, by pointer, keyboard or the data table.
onHiddenChange(hidden: string[]) => voidCalled when the legend hides or shows a series.
onActiveChange(index: number | null) => voidCalled as the hovered or focused row changes, or null when it leaves.
onReady(chart: EChartsType) => voidCalled once with the ECharts instance, e.g. to add event listeners.
export type Selection<TDatum> = {
  /** Index into the data you passed in, even when a brush shows a subset. */
  dataIndex: number;
  datum: TDatum;
  seriesKey: string | null;
  source: "pointer" | "keyboard" | "table";
  /** For a grouped segment (a donut's "Other"): the indexes of every row it stands for. `dataIndex` is the largest. */
  members?: number[] | undefined;
};

export type TooltipContext<TDatum> = {
  datum: TDatum;
  /** Index into the data you passed in. */
  dataIndex: number;
  /** Visible series at this index. `value` is your raw value; `share` is its part of the row in 100% mode. */
  series: { key: string; label: ReactNode; value: number | null; share?: number | null | undefined; color: string; selected: boolean }[];
};

Parts and styling hooks

Each part carries a data-slot attribute. Theme rules inside the chart are one attribute selector deep, so a selector such as .my-chart [data-slot="chart-title"] overrides them. These are the slots in the files this chart installs; parts a chart doesn't use are simply absent from its markup.

chartchart-bodychart-descriptionchart-eyebrowchart-footerchart-headerchart-headingchart-legendchart-legend-itemchart-legend-labelchart-legend-swatchchart-legend-valuechart-livechart-mainchart-plotchart-readoutchart-statchart-stat-notechart-stat-valuechart-statechart-state-boxchart-state-messagechart-statschart-tablechart-table-scrollchart-takeawaychart-titlechart-tooltipodometerodometer-digitodometer-glyphsodometer-reelodometer-signpartial-notereadout-deltareadout-unitreadout-valuesr-onlytooltip-indicatortooltip-memberstooltip-rowtooltip-titletooltip-value

Props every chart shares

Header, states, legend, tooltip, formatting, motion, sound and controlled interaction state. They work the same on every Instrument chart and both engines. The guide explains colours, controlled state and accessibility.

Show all 32 shared props
Props every chart shares
PropTypeDescription
data*TDatum[]Your rows, as they are. Missing values (null, undefined, NaN) stay missing and are never drawn as zero.
localestringBCP 47 locale. Defaults to "en-US" so server and client render the same text.
timeZonestringIANA time zone for dates. Defaults to "UTC" so server and client agree.
configChartConfigPer-series label, colour, icon, format and style, keyed by series key. shadcn ChartConfig works as it is.
eyebrowReactNodeSmall label above the title.
titleReactNodeCard title. A string also names the chart for screen readers.
descriptionReactNodeA line under the title.
takeawayReactNode | ((summary: string) => ReactNode) | falseThe sentence under the title. Computed from the data by default; pass text, a function of the computed sentence, or false to hide it.
ariaDescriptionstringAccessible summary for screen readers. Computed from the data by default.
motionMotionPreference"full" (default), "subtle" or "off". Reduced-motion settings always win.
motionOptionsMotionOptionsWhen the entrance plays.
soundbooleanSound cues on hover, scrub and select. Plays only if the visitor has also turned sound on for the page.
densityDensity"comfortable" (default) or "compact" for dashboards.
legendLegendOptions | falseLegend position, alignment, shape and click action, or false to hide it.
tooltipTooltipOptions<TDatum> | falseTooltip position, indicator, cursor and custom content, or false to turn it off.
valueFormatter(value: number) => stringValues formatted for display. Series formatters in config win.
loadingbooleanShow the loading state. Over existing data, the old marks stay dimmed instead of vanishing.
errorstring | nullAn error message. Shows the error state in place of the plot.
emptyStateReactNodeShown instead of the plot when there is no data.
loadingStateReactNodeShown while loading is true and there is no data yet.
errorStateReactNodeShown when error is set.
selectednumber | nullControlled and uncontrolled interaction state. Point selection (selected) pins one row by its index in data. Series selection (selectedSeries) picks one series and dims the others. They are separate: picking a row doesn't pick a series.
defaultSelectednumber | nullInitial selected row when uncontrolled.
hiddenstring[]Controlled hidden series keys.
defaultHiddenstring[]Series hidden at first when uncontrolled.
activeIndexnumber | nullControlled hover or focus index, for syncing several charts on one cursor.
palette"theme" | "shadcn"Series colours: "theme" (default) uses the theme's designed palette; "shadcn" uses your --chart-1..5. --bc-series-N always wins. You can also opt a whole section in with the class bc-use-shadcn-colors.
tablebooleanShow the "Show data table" disclosure. On by default.
statsChartStat[]A row of figures under the title, for dashboard cards and blocks.
classNamestringClasses on the card, for spacing and layout.
heightnumberHeight of the plot area in px. The frame sizes around it.