Pie Chart

Documentation Index

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

Pie and donut charts with gradients, labels, and glow effects

Installation

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

Usage

The pie chart is composable. <EvilPieChart> is the container; compose the parts you need — <EvilPieChart.Legend>, <EvilPieChart.Tooltip>, <EvilPieChart.Background>, and one <EvilPieChart.Pie> — as children. Each <EvilPieChart.Pie> owns its shape props (innerRadius, paddingAngle, cornerRadius, …), isClickable, and glowingSectors, so one chart can mix any combination.

<script lang="ts">
	import { EvilPieChart } from '$lib/components/evilcharts/charts/layerchart-pie-chart';
	import { type ChartConfig } from '$lib/components/evilcharts/ui/layerchart-chart';
</script>
<script lang="ts">
	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;
</script>
<EvilPieChart {data} dataKey="visitors" nameKey="browser" config={chartConfig}>
	<EvilPieChart.Legend isClickable />
	<EvilPieChart.Tooltip />
	<EvilPieChart.Pie isClickable innerRadius={60} paddingAngle={4} cornerRadius={8}>
		<EvilPieChart.Label />
	</EvilPieChart.Pie>
</EvilPieChart>

Interactive Selection

Add isClickable to <EvilPieChart.Pie> (and <EvilPieChart.Legend>) to make sectors selectable. Handle changes with the onSelectionChange callback on <EvilPieChart>:

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

Loading State

Examples

Examples with different configurations. Customize innerRadius, paddingAngle, cornerRadius, and more.

Gradient Colors

Donut Chart

Padded Sectors

Labels

Glowing Sectors

Dither rendering

Set renderStyle="dither" on the existing pie root for ordered-dither sectors. Donut holes, padding, rounded corners, labels, tooltips, selection, loading, and sweep motion keep their existing behavior. Use ditherVariant on <Pie /> to override the root texture.

The renderer is independently implemented for EvilCharts SV and inspired by Dither Kit by Boring Software.

API Reference

Props are grouped by the part they belong to.

EvilPieChart

The root container. Owns the data, shared selection state, and loading skeleton; all visuals are composed as its children.

PropTypeDefaultDescription
data*TData[]

An array of objects, one per sector (TData extends Record<string, unknown>).

dataKey*keyof TData & string

Data key for sector values — typically numbers that set sector size.

nameKey*keyof TData & string

Data key for sector names — the strings used in labels and legend.

config*ChartConfig

Defines each sector’s colors. Keys should match the values from your nameKey field.

children*Snippet

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

accessibilityChartAccessibility

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

classNamestring

Extra CSS classes for the chart container.

defaultSelectedSectorstring | nullnull

Sector name selected by default.

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 a placeholder animation while data loads.

renderStyle svg| dither"svg"Selects the SVG or ordered-dither renderer.
ditherVariant gradient| dotted| hatched| solid"gradient"Default texture for dithered sectors.
ditherCellSizenumber2Dither cell size in CSS pixels.
bloom off| low| high| aura"off"Optional bounded glow around dither pixels.
chartPropsComponentProps<typeof PieChart>

Extra props forwarded to the underlying LayerChart Chart. See the LayerChart Chart documentation .

Pie

The pie series. Self-contained — it generates its own gradients and glow filters, so any number of pies coexist on a page without style collisions. Compose a <Label /> inside it to draw sector labels.

PropTypeDefaultDescription
innerRadiusnumber | string0

Inner radius of the pie; set above 0 for a donut. Number (pixels) or percentage string.

outerRadiusnumber | string"80%"

Outer radius of the pie. Number (pixels) or percentage string.

cornerRadiusnumber0

Corner radius of each sector, in pixels.

paddingAnglenumber0

Padding between sectors, in degrees. Negative values overlap sectors.

startAnglenumber0

Starting angle, in degrees (0 is 3 o’clock, 90 is 12 o’clock).

endAnglenumber360

Ending angle, in degrees. Below 360 draws a partial pie.

isClickablebooleanfalse

Lets users click sectors to select/deselect them; selecting one dims the rest.

glowingSectorsstring[][]

Array of sector names (values from your nameKey field) to give a smooth outer glow.

childrenSnippet

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

piePropsOmit<ComponentProps<typeof Pie>, "data" | "dataKey" | "nameKey">

Escape hatch for raw props forwarded to the underlying LayerChart Arc. See the LayerChart Arc documentation .

Label

Per-sector labels composed inside a <Pie />. Renders nothing itself — the parent <Pie /> reads its props and draws the label list over the sectors.

PropTypeDefaultDescription
dataKeystring

Data key for label text. Falls back to the chart’s dataKey when omitted.

labelListPropsOmit<ComponentProps<typeof LabelList>, "dataKey">

Escape hatch for label props. See the LayerChart Text documentation .

Tooltip

The hover tooltip. Hidden automatically while the chart loads.

PropTypeDefaultDescription
variant default| frosted-glass"default"

Visual style of the tooltip surface.

roundness sm| md| lg| xl"lg"

Border-radius of the tooltip.

defaultIndexnumber

Shows the tooltip by default at the given sector index.

Legend

The sector legend. When isClickable is set, each entry toggles selection of its sector.

PropTypeDefaultDescription
variant"square" | "circle" | "circle-outline" | "rounded-square" | "rounded-square-outline" | …

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 pattern behind the pie. Compose it before the <Pie /> so it sits under the sectors.

PropTypeDefaultDescription
variantBackgroundVariant"dots"

The background pattern style.