Pie Chart

Simple static & beautifully designed pie charts with donut, gradient, and glow effects

Basic Chart

Installation

npx shadcn@latest add @evilcharts/pie-chart

Usage

import { EvilPieChart } from "@/components/evilcharts/charts/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;

Interactive Selection

When isClickable is enabled, you can use the onSelectionChange callback to handle selection events:

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

Loading State

isLoading='true'
Loading

Examples

Below are some examples of the pie chart with different configurations. You can customize the innerRadius, paddingAngle, cornerRadius, and other properties.

Gradient Colors

gradient colors

Donut Chart

innerRadius={60}

Padded Sectors

paddingAngle={4} cornerRadius={8}
innerRadius={60} paddingAngle={-20} cornerRadius={100}

Labels

showLabels={true}

Glowing Sectors

glowingSectors={['chrome', 'safari']}

API Reference

dataRequired

Data used to display the chart. An array of objects where each object represents a sector.

type: TData[] where TData extends Record<string, unknown>

dataKeyRequired

The key from your data objects to use for sector values (typically numeric values that determine sector size).

type: keyof TData & string

nameKeyRequired

The key from your data objects to use for sector names (typically string values used for labels and legend).

type: keyof TData & string

chartConfigRequired

Configuration object that defines the chart's sectors. Each key should match a value from your nameKey field, with corresponding colors.

type: ChartConfig

className

Additional CSS classes to apply to the chart container.

type: string

innerRadius

The inner radius of the pie. Set to a value greater than 0 to create a donut chart. Can be a number (pixels) or percentage string.

type: number | string

default: 0

outerRadius

The outer radius of the pie. Can be a number (pixels) or percentage string.

type: number | string

default: "80%"

cornerRadius

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

type: number

default: 0

paddingAngle

The angle of padding between sectors in degrees.

type: number

default: 0

startAngle

The starting angle of the pie chart in degrees (0 is 3 o'clock, 90 is 12 o'clock).

type: number

default: 0

endAngle

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

type: number

default: 360

showLabels

Whether to display labels on each sector.

type: boolean

default: false

labelKey

The key from your data objects to use for label text when showLabels is enabled. If not provided, uses the dataKey value.

type: keyof TData & string

labelListProps

Additional props to customize the label list appearance and behavior.

type: Omit<ComponentProps<typeof LabelList>, "dataKey">

Read the Recharts LabelList documentation for available props.

hideTooltip

Whether to hide the tooltip on hover.

type: boolean

default: false

tooltipRoundness

Controls the border-radius of the tooltip.

type: "sm" | "md" | "lg" | "xl"

default: "lg"

tooltipVariant

Controls the visual style of the tooltip.

type: "default" | "frosted-glass"

default: "default"

tooltipDefaultIndex

When set, the tooltip will be visible by default at the specified data point index.

type: number

legendVariant

The visual style variant for the legend indicators.

type: "square" | "circle" | "circle-outline" | "rounded-square" | "rounded-square-outline" | "vertical-bar" | "horizontal-bar"

hideLegend

Whether to hide the chart legend.

type: boolean

default: false

backgroundVariant

Background pattern variant to display behind the chart.

type: BackgroundVariant

isClickable

Enables interactive clicking on sectors to select/deselect them. Selected sectors expand slightly and unselected sectors dim.

type: boolean

default: false

onSelectionChange

Callback function that is called when a sector is selected or deselected. Receives an object with dataKey (sector name) and value (sector value), or null when deselected.

Note: This prop is only available when isClickable is set to true.

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

isLoading

Shows a loading placeholder animation when data is being fetched.

type: boolean

default: false

glowingSectors

Array of sector names (values from your nameKey field) that should have a glowing effect applied. Creates a smooth outer glow around the specified sectors.

type: string[]

default: []

chartProps

Additional props to pass to the underlying Recharts PieChart component.

type: ComponentProps<typeof PieChart>

Read the Recharts PieChart documentation for available props.

pieProps

Additional props to pass to the underlying Recharts Pie component.

type: Omit<ComponentProps<typeof Pie>, "data" | "dataKey" | "nameKey">

Read the Recharts Pie documentation for available props.