Skip to content
Charts

Pie Chart

Full pie. Default and Motion variants.

Examples

Installation

Default is a ready-made wrapper from the registry. Motion is the composable engine at @cronus-ui/ui/charts (peer visx + motion).

bash
npx cronus-ui add pie-chart
tsx
import { PieChart } from "@cronus-ui/ui";

Usage

Share hoveredIndex between PieChart and Legend so hover highlights the matching slice and row.

tsx
import { PieChart, PieSlice, Legend, LegendItem, LegendMarker, LegendLabel, LegendValue } from "@cronus-ui/ui/charts";
const [hovered, setHovered] = useState<number | null>(null);
<div className="flex items-center gap-8">
<PieChart data={slices} hoveredIndex={hovered} onHoverChange={setHovered}>
{slices.map((_, i) => <PieSlice index={i} key={i} />)}
</PieChart>
<Legend items={items} hoveredIndex={hovered} onHoverChange={setHovered}>
<LegendItem>
<LegendMarker />
<LegendLabel />
<LegendValue />
</LegendItem>
</Legend>
</div>

Components

Motion API — compose these under the chart root. Default wrapper props are in Default API below.

PieChart

Full pie. Pads the SVG by hoverOffset so translated slices are not clipped.

Skip PieChartProps props table
PropTypeDefaultDescription
data*
PieData[]label, value, optional color/fill.
size
numberPixel size. Falls back to parent width.
innerRadius
number0Donut hole. 0 is a solid pie.
padAngle
number0Gap between slices in radians.
cornerRadius
number0Rounded slice edges.
hoveredIndex
number | nullControlled hover.
hoverOffset
number10Translate/grow distance and SVG padding.

PieSlice

One slice. Hover translate (default), grow, or none.

Skip PieSliceProps props table
PropTypeDefaultDescription
index*
numberIndex in data.
color
stringOverride. Falls back to data.color or --chart-1…5.
fill
stringPattern/gradient url.
hoverEffect
"translate" | "grow" | "none""translate"Hover motion.
showGlow
booleantrueGlow on hover.

PieCenter

Hub statistic. Swaps to the hovered slice label/value.

Skip PieCenterProps props table
PropTypeDefaultDescription
defaultLabel
string"Total"Label when nothing is hovered.
prefix
stringPrefix before the number.
children
(ctx) => ReactNodeCustom hub renderer.

Legend

Composable side legend. Map `LegendItem` (marker, label, value, optional progress) over `items`. Share `hoveredIndex` with the chart for bidirectional highlight.

Skip LegendProps props table
PropTypeDefaultDescription
items*
LegendItemData[]Label, value, color, optional maxValue.
hoveredIndex
number | nullControlled hover.
onHoverChange
(index: number | null) => voidHover callback.
title
stringHeading above the list.
children*
ReactElementA single LegendItem template, cloned per item.

Legend hover

Controlled hoveredIndex is bidirectional: legend rows fade unselected slices, and slice hover highlights the matching row.

tsx
const [hovered, setHovered] = useState<number | null>(null);
<PieChart data={slices} hoveredIndex={hovered} onHoverChange={setHovered}>
{slices.map((_, i) => <PieSlice index={i} key={i} />)}
</PieChart>

Data format

ts
type PieData = { label: string; value: number; color?: string; fill?: string };
const slices: PieData[] = [
{ label: "Direct", value: 4200 },
{ label: "Organic", value: 3100 },
{ label: "Referral", value: 1900 },
];

Theming

Motion charts read `--chart-*` aliases that map onto Cronus semantic tokens (`--cronus-chart-1`…`--cronus-chart-5`, `--cronus-border`, `--cronus-fg`, surfaces). Override the aliases or the tokens — never palette scales (`bg-zinc-900`). Default wrappers use `ChartConfig` with `var(--cronus-chart-*)` / `var(--cronus-primary)`. defaultPieColors cycles `--chart-1`…`--chart-5`.

Full token reference: Theming.

Dependencies

Default needs the recharts peer. Motion needs visx (and sometimes d3) as optional peers — install only what this chart uses.

bash
bun add recharts
bash
bun add @visx/shape @visx/responsive d3-shape motion

Default API

Generated from the Default wrapper's exported types. Motion subcomponents are documented above.

PieChartProps

Extends HTMLAttributes<HTMLDivElement>

Skip PieChartProps props table
PropTypeDefaultDescription
data*
PieChartItem[]
series*
ChartSeries[]