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

Installation

npx shadcn-svelte@latest add https://evilcharts-sv.vercel.app/r/echarts-pie-chart.json

Usage

The ECharts pie chart is composable, sharing the LayerChart sibling’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.

<script lang="ts">
	import {
		EChartsPieChart,
		type ChartConfig
	} from '$lib/components/evilcharts/charts/echarts-pie-chart/index.js';
</script>
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} 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 difference is under the hood: these compound children are declarative configuration slots rather than visual DOM nodes. The root reads their props and compiles an ECharts option, which ECharts paints with Canvas by default or SVG when renderer="svg".

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.

SVG Renderer

Pass renderer="svg" to the chart root to opt into ECharts’ SVG renderer. Omit it to use the default Canvas renderer.

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}
	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

Examples

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

Gradient Colors

Donut Chart

Padded Sectors

Labels

Outside Labels

Ordered dither

Set renderStyle="dither" to use the independent ordered-dither treatment inspired by Dither Kit. Labels, tooltips, selection, and the ECharts renderer stay intact.

API Reference

The chart has several parts; the props below are grouped by part. Regardless of renderer, each part is declarative config the root compiles, but the API mirrors the LayerChart sibling 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*Snippet

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

classstring

Extra CSS classes for the chart container.

renderer canvas| svg"canvas"

Rendering engine used by ECharts. Use "svg" for an SVG-backed chart surface; omit the prop to keep the Canvas default.

renderStyle native| dither"native"

Selects native ECharts paint or EvilCharts’ ordered-dither rendering.

ditherVariant gradient| dotted| hatched| solid"gradient"

Default ordered-dither pattern used by the chart’s sectors.

ditherCellSizenumber2

Dither cell size in CSS pixels.

bloom off| low| high| aura"off"

Optional glow applied to dithered sectors. It has no effect in native rendering mode.

animationbooleantrue

Master switch for the intro draw-in. Pass false to render instantly. Not on the LayerChart sibling — it’s the ECharts off-switch. The OS reduce-motion preference disables the entrance automatically.

defaultSelectedSectorstring | nullnull

The sector selected on first render.

selectedSectorstring | null

Controlled selection. Leave it undefined to let the chart manage selection; pass null to clear a controlled selection. Pair it with onSelectionChange to keep your own UI, such as a custom legend or stat cards, 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 .

accessibilityChartAccessibility

Names and optionally describes the chart wrapper. It remains a group, so interactive legends and marks stay available to assistive technology.

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.

childrenSnippet

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
position inside| 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
variant default| frosted-glass"default"

The visual style of the tooltip surface.

roundness sm| 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.

position fixed| 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 chart surface. Its presence enables the legend; omit it and none shows. When isClickable is set, each entry toggles selection of its sector.

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

The visual style of the legend indicators.

align left| center| right"center"

Horizontal placement of the legend.

verticalAlign top| 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".