Pie Chart

Documentation Index

Fetch the complete documentation index at: /llms.txt. Use this file to discover all available pages before exploring further.

Static, beautifully designed pie charts with donut, gradient, and pop-out selection, powered by Apache ECharts

Basic Chart

Installation

npx shadcn@latest add @evilcharts/echarts-pie-chart

Usage

The ECharts pie chart is composible, sharing the Recharts twin's API shape. <EChartsPieChart> is the container, and every part hangs off it as a compound member — <EChartsPieChart.Legend>, <EChartsPieChart.Tooltip>, <EChartsPieChart.Background>, and one <EChartsPieChart.Pie> — so a single import gives you the whole chart. The <EChartsPieChart.Pie> carries its own shape props (innerRadius, paddingAngle, cornerRadius, …) and an isClickable flag.

import { EChartsPieChart, type ChartConfig } from "@/components/evilcharts/charts/echarts-pie-chart";
const data = [
  { browser: "chrome", visitors: 275 },
  { browser: "safari", visitors: 200 },
  { browser: "firefox", visitors: 187 },
];
 
const chartConfig = {
  chrome: {
    label: "Chrome",
    colors: { light: ["#3b82f6"], dark: ["#60a5fa"] },
  },
  safari: {
    label: "Safari",
    colors: { light: ["#10b981"], dark: ["#34d399"] },
  },
  firefox: {
    label: "Firefox",
    colors: { light: ["#f59e0b"], dark: ["#fbbf24"] },
  },
} satisfies ChartConfig;
<EChartsPieChart data={data} dataKey="visitors" nameKey="browser" config={chartConfig}>
  <EChartsPieChart.Legend isClickable />
  <EChartsPieChart.Tooltip />
  <EChartsPieChart.Pie isClickable innerRadius={60} paddingAngle={4} cornerRadius={8}>
    <EChartsPieChart.Label />
  </EChartsPieChart.Pie>
</EChartsPieChart>

The one real difference is under the hood: ECharts renders to a <canvas>, so these children never mount as DOM. The root reads their props and compiles them into the ECharts option — same JSX, same presence semantics (omit a part and it won't render), same behavior, just declarative config instead of live DOM nodes.

The config is the same contract as every EvilCharts chart — each key maps a sector name to a label and a per-theme colors array. See Chart Config for the full shape. Colors resolve from your CSS variables at runtime, so dark mode works with no extra wiring.

Interactive Selection

Add isClickable to the <Pie> (and <Legend>) to make sectors selectable. Selecting one pops it radially outward — the offset-slice look — while the others dim; select again to reset. Handle selection events with the onSelectionChange callback on <EChartsPieChart>:

<EChartsPieChart
  data={data}
  dataKey="visitors"
  nameKey="browser"
  config={chartConfig}
  onSelectionChange={(selection) => {
    if (selection) {
      console.log("Selected:", selection.dataKey, "Value:", selection.value);
    } else {
      console.log("Deselected");
    }
  }}
>
  <EChartsPieChart.Legend isClickable />
  <EChartsPieChart.Tooltip />
  <EChartsPieChart.Pie isClickable />
</EChartsPieChart>

Loading State

isLoading='true'

Examples

Examples of the pie chart in different configurations. Customize innerRadius, paddingAngle, cornerRadius, and more.

Gradient Colors

gradient colors

Donut Chart

innerRadius={60}

Padded Sectors

paddingAngle={4} cornerRadius={8}
innerRadius={60} paddingAngle={-25} cornerRadius={99}

Labels

<Label />

Outside Labels

<Label position="outside" />

API Reference

The chart has several parts; the props below are grouped by part. On canvas each part is declarative config the root compiles, but the API mirrors the Recharts twin one-to-one.

EChartsPieChart

The root container. It owns the data, shared selection state, loading skeleton, and intro reveal. Everything visual is composed as its children and compiled into the ECharts option.

PropTypeDefaultDescription
data*TData[]

The chart data — an array of objects, one per sector (TData extends Record<string, unknown>).

dataKey*keyof TData & string

The data key for sector values — typically the numbers that size each sector.

nameKey*keyof TData & string

The data key for sector names, used in labels and legend. Each name must match a key in config.

config*ChartConfig

Defines the chart's sectors. Each key matches a value from your nameKey field, with a label and a per-theme colors array. Same contract as every EvilCharts chart — see Chart Config.

children*ReactNode

The composed chart parts — <Legend />, <Tooltip />, <Background />, and one <Pie />.

classNamestring

Extra CSS classes for the chart container.

animationbooleantrue

Master switch for the intro draw-in. Pass false to render instantly. Not on the Recharts twin — it's the canvas off-switch. The OS reduce-motion preference disables the entrance automatically.

defaultSelectedSectorstring | nullnull

The sector selected on first render.

selectedSectorstring | null

Controlled selection. When provided it overrides the internal state, so a parent can drive which sector is selected — pair it with onSelectionChange to keep your own UI (a custom legend, stat cards) and the chart in sync.

onSelectionChange(selection: { dataKey: string; value: number } | null) => void

Fires when a sector is selected or deselected via a clickable <Pie /> sector or <Legend /> entry. Receives an object with dataKey (sector name) and value (sector value), or null when deselected.

isLoadingbooleanfalse

Shows the animated loading skeleton while data loads.

chartOptionsRecord<string, unknown>

Escape hatch merged over the underlying ECharts option object. See the ECharts option documentation.

Pie

The pie series. Carries its own shape and clickability. When clickable, the selected sector pops radially outward. Compose a <Label /> inside it to draw labels on each sector.

PropTypeDefaultDescription
variant"gradient""gradient"

The fill style for the sectors. Each paints a diagonal gradient from its config colors — solid for a single color, or a multi-stop gradient across the sector.

innerRadiusnumber | string0

The pie's inner radius. Set above 0 for a donut. Accepts a number (pixels) or percentage string.

outerRadiusnumber | string"80%"

The pie's outer radius. Accepts a number (pixels) or percentage string.

cornerRadiusnumber0

The border radius for the corners of each sector in pixels.

paddingAnglenumber0

The space between sectors. Positive values draw a constant-width, background-colored gap (parallel-edged from rim to center, not a wedge-shaped angular pad). Negative values overlap sectors into petals, kept distinct by a background-colored border.

startAnglenumber0

The starting angle of the pie in degrees (0 is 3 o'clock, 90 is 12 o'clock). Sectors sweep counterclockwise from here.

endAnglenumber360

The ending angle of the pie in degrees. Set to less than 360 for a partial pie.

isClickablebooleanfalse

Enables clicking a sector to select/deselect it. The selected sector pops radially outward from the center while the others dim.

childrenReactNode

Optional <Label /> composition that draws labels on each sector.

Label

Per-sector labels composed inside a <Pie />. It renders nothing on its own — the parent <Pie /> reads its props and draws the labels, either on each sector or outside the rim with a leader line.

PropTypeDefaultDescription
positioninside|outside"inside"

Where the labels sit. "inside" draws the value on each sector; "outside" moves the sector's name past the rim with a leader line (the classic ECharts pie layout). When "outside" and no dataKey is set, the label shows the sector's name from config instead of its value.

dataKeystring

The data key for label text. When omitted, inside labels fall back to the chart's dataKey (the sector value), outside labels to the sector's name.

Tooltip

The hover tooltip. Its presence enables the tooltip; omit it and none shows. Hidden automatically while the chart is loading.

PropTypeDefaultDescription
variantdefault|frosted-glass"default"

The visual style of the tooltip surface.

roundnesssm|md|lg|xl"lg"

Controls the border-radius of the tooltip.

defaultIndexnumber

When set, the tooltip is visible by default at the specified sector index.

positionfixed|variable"variable"

How the tooltip is anchored. "variable" follows the pointer (the default); "fixed" pins the tooltip near the top and only tracks the pointer's X.

Legend

The sector legend, rendered as HTML over the canvas. Its presence enables the legend; omit it and none shows. When isClickable is set, each entry toggles selection of its sector.

PropTypeDefaultDescription
variantsquare|circle|circle-outline|rounded-square|rounded-square-outline|vertical-bar|horizontal-bar

The visual style of the legend indicators.

alignleft|center|right"center"

Horizontal placement of the legend.

verticalAligntop|middle|bottom"bottom"

Vertical placement of the legend.

isClickablebooleanfalse

Lets each legend entry toggle selection of its sector.

Background

An optional decorative SVG pattern drawn behind the pie. Its presence renders the pattern; omit it and none shows.

PropTypeDefaultDescription
variantBackgroundVariant"dots"

The background pattern style — one of "dots", "grid", "cross-hatch", "diagonal-lines", "plus", "falling-triangles", "4-pointed-star", "tiny-checkers", "overlapping-circles", "wiggle-lines", or "bubbles".