Donut Chart

Preview

Install

Add it with the shadcn CLI, or copy the source manually.

$ bunx --bun shadcn add @beui/donut-chart

API Reference

DonutChart

segments
readonly DonutSegment[]
Default—
thickness?
number

Ring thickness in viewBox units; the chart is 200 wide.

Default—
gap?
number

Degrees of empty space between neighbouring segments.

Default—
activeId?
string | null

Focused segment, shared by the ring, center, and legend. Controlled.

Default—
defaultActiveId?
string | null
Default—
onActiveChange?
((id: string | null) => void)
Default—
onSelect?
((id: string) => void)

Called when a legend item is clicked.

Default—
selectedId?
string | null

Marks a legend item as pressed.

Default—
formatValue?
((value: number) => string)
Default—
label?
string

Accessible name for the chart.

Default—
labels?
Partial<{ label: string; total: string; }>

Override any built-in string.

Default—
className?
string
Default—

DonutChartCenter

children?
((segment: PlacedSegment | null, total: number) => ReactNode)

Custom content for the hole. Receives the focused segment, or null when nothing is focused, and the total. Defaults to a rolling value and caption.

Default—
totalLabel?
ReactNode

Caption under the total when nothing is focused.

Default—
className?
string
Default—

DonutChartLegend

renderDetail?
((segment: PlacedSegment) => ReactNode)

Extra line under each name, such as terms or a note.

Default—
renderValue?
((segment: PlacedSegment) => ReactNode)

Trailing value. Defaults to the share and formatted value.

Default—
className?
string
Default—

DonutChartPlot

children?
ReactNode

Centered overlay, usually `DonutChartCenter`.

Default—
className?
string
Default—

Updated