shadcn.io is not affiliated with official shadcn/ui
About
Use it when a card should answer one question at a time: what was May's share? The reader picks a month and the donut highlights that slice and prints its value. When all values matter at once, a labeled pie or a bar chart shows them without a control.
Five monthly slices sit on a ring. The selected month's slice extends past the others, a thin band of the same color wraps it, and the center shows its count above "Visitors".
Installation
Usage
import { ChartPieInteractive } from "@/components/charts/chart-pie-interactive";<ChartPieInteractive />Customize
activeMonthstate comes from<Select onValueChange>;activeIndexis derived withuseMemo.<Pie shape={renderPieShape}>draws the active sector as two<Sector>s, one 10px longer and one band from 12px to 25px out.- The
<Label>printsdesktopData[activeIndex].desktopin the center. <ChartStyle config={chartConfig} id={id} />on the card exposes the month colors to the select, outsideChartContainer.
FAQ
How does the select drive the chart?
activeMonth is React state that the <Select>'s onValueChange sets. activeIndex is derived from it, and the shape function on <Pie> reads it to draw the active sector.
How are the bigger slice and the outer ring drawn?
The shape function returns a <g> for the active index with two <Sector>s: one with outerRadius + 10, one from outerRadius + 12 to outerRadius + 25. Other sectors render normally.
What sets the number in the middle?
The <Label> inside <Pie> prints desktopData[activeIndex].desktop at the viewBox center, so it follows the select.
How do the select's swatches match the slices?
The card renders <ChartStyle config={chartConfig} id={id} /> and carries data-chart={id}, so the --color-<month> variables reach the select outside ChartContainer. Each <SelectItem> draws a span with backgroundColor: var(--color-<month>).
API Reference
ChartContainer
configChartConfig
Each series by its data key: its label, an icon, and a color (or a * theme color per light and dark), read by the tooltip and legend and set * as --color-<key>.
initialDimension?{ height: number; width: number; }
The size it renders at before it's measured, so the first paint isn't * empty.
- Type
{ height: number; width: number; }- Default
INITIAL_DIMENSION
className?string
Merged with the part's classes.
ChartLegend
ChartLegendContent
<div>
hideIcon?boolean
Hides each series' icon (from config), leaving its color swatch.
- Default
false
nameKey?string
The key in each legend item's data to look its label up by in config. * Defaults to the item's dataKey.
className?string
Merged with the part's classes.
ChartStyle
<style>
configChartConfig
The chart config whose colors it writes as --color-<key> variables.
idstring
The element's id.
ChartTooltip
ChartTooltipContent
<div>
hideIndicator?boolean
Hides each item's color indicator.
- Default
false
hideLabel?boolean
Hides the tooltip's label, the hovered point's.
- Default
false
indicator?"dashed" | "dot" | "line"
The color indicator's shape: a dot, a line or dashed.
- Type
"dashed" | "dot" | "line"- Default
"dot"
labelFormatter?(label: any, payload: TooltipPayload) → React.ReactNode
Formats the tooltip's label; its value is untyped, as in recharts 3.8.
- Type
(label: any, payload: TooltipPayload) → React.ReactNode- Parameters
label– anypayload– TooltipPayload- Returns
React.ReactNode
labelKey?string
The key in the data to read the label from, looked up in config.
nameKey?string
The key in each item's data to look its name up by in config.
className?string
Merged with the part's classes.
Related
Donut Chart with Active Sector
Pie chartsA donut with one slice pulled out as active.
Donut Chart with Text
Pie chartsA donut with the total written in its center.
Interactive Area Chart
Area chartsThree months of daily visitors with a time range select.
Interactive Bar Chart
Bar chartsThree months of daily bars, switched between two series.
Interactive Line Chart
Line chartsThree months of daily values, switched between two series.
Pie Chart
Pie chartsA plain pie, one slice per browser.