Pie Chart

A beautiful, accessible pie and donut chart component with native center content support, smooth animations, and keyboard navigation. Perfect for visualizing proportions and distributions.

Pie, Donut & Semi-circle
Center Content API
Smooth Animations
Keyboard Navigation
TypeScript
Responsive

Basic Example

A donut chart showing market share data with click interactions and center content

Loading...
Selected: Click a slice to select
Variant:

Installation

Get started with the PieChart component in just a few steps.

Quick Install
bash
npx mario-charts@latest add pie-chart
Zero Lock-in Philosophy
The component is fully yours to own, modify, and customize.

Variants Comparison

Compare all three chart variants: classic pie, donut with center content, and semi-circle gauge

Pie

Loading...

Donut

Loading...

Semi-circle

Loading...

Custom Center Content

The centerContent prop accepts either a ReactNode or a render function that receives the total and all items

Static Content

Loading...

Dynamic Content

Loading...

Budget Breakdown

A complete budget visualization with custom colors and interactive controls

Loading...
Variant:

Chart States

Built-in handling for loading, error, and empty states

Loading

Error

Chart Error
Failed to load chart data

Empty

No Data
There's no data to display

Performance Considerations

Tips for optimal performance when working with large datasets

Best Practices

  • For datasets with 50+ slices, aggregate smaller values into an “Others” category
  • Disable animations with animation={false} for faster rendering
  • The component uses useMemo to cache expensive slice calculations
  • ResizeObserver ensures efficient responsive behavior without constant re-renders

Development Warnings

In development mode, the component logs warnings for invalid data values (NaN, Infinity, or non-numeric types). Check the browser console if your chart displays unexpected results.

API Reference

Complete reference for all PieChart props

PropTypeDefaultDescription
datarequired
readonly T[]Array of data objects to display in the chart
valuerequired
keyof TKey from data object to use for slice values
labelrequired
keyof TKey from data object to use for slice labels
variant
'pie' | 'donut' | 'semi''donut'Visual style - classic pie, donut with center hole, or semi-circle gauge
innerRadius
number0.6Inner radius as percentage of outer radius (0-1). Only applies to donut/semi variants
centerContent
ReactNode | ((data) => ReactNode)Content to display in the center of donut/semi charts. Can be a static element or render function
colors
readonly string[]DEFAULT_COLORSArray of colors to use for slices
height
number300Height of the chart in pixels
loading
booleanfalseShow loading state with circular skeleton
error
string | nullnullError message to display
animation
booleantrueEnable entrance and hover animations
onSliceClick
(data: T, index: number) => voidCallback fired when a slice is clicked
className
stringAdditional CSS classes to apply to the container