Pie Chart
A config-first part-to-whole donut. Hand it an array of { label, value } and it renders slices in fixed slot colors, an always-present legend, per-slice hover tooltips with percent-of-total, and an accessible data table. Pass totalLabel to fill the donut center with the summed total.
- Organic4.2k
- Direct3.1k
- Referral1.9k
- Social1.4k
- Email800
| Label | Value | Percent |
|---|---|---|
| Organic | 4.2k | 36.8% |
| Direct | 3.1k | 27.2% |
| Referral | 1.9k | 16.7% |
| Social | 1.4k | 12.3% |
| 800 | 7% |
Installation
Copy the piece and its math helper into your app — they compile with your build and the code is yours:
puzzle add piece pie-chart
A pie shows positive parts of a whole, so zero and negative values are dropped. Reach for it only for at-a-glance proportions with a handful of slices — for comparing close values, a bar chart is clearer. Requires the pieces.css tokens merged into your app styles (see Introduction).
Usage
import PieChart from '@/components/ui/PieChart.pzl';
<PieChart data={ trafficData } label="Traffic by source" totalLabel="Sessions" />Plain pie
- Organic4.2k
- Direct3.1k
- Referral1.9k
- Social1.4k
- Email800
| Label | Value | Percent |
|---|---|---|
| Organic | 4.2k | 36.8% |
| Direct | 3.1k | 27.2% |
| Referral | 1.9k | 16.7% |
| Social | 1.4k | 12.3% |
| 800 | 7% |
Legend and folding
The legend is always present — slices are the series, so color-matching alone is never required. When the data has more than eight slices, the seven largest are kept and the rest fold into a single Other slice, so the palette is never cycled past its eight validated slots.
- United States5.2k
- Germany3.1k
- India2.6k
- Brazil1.8k
- Japan1.5k
- France1.2k
- Canada950
- Other1.6k
| Label | Value | Percent |
|---|---|---|
| United States | 5.2k | 28.9% |
| Germany | 3.1k | 17.2% |
| India | 2.6k | 14.5% |
| Brazil | 1.8k | 10% |
| Japan | 1.5k | 8.3% |
| France | 1.2k | 6.7% |
| Canada | 950 | 5.3% |
| Other | 1.6k | 9.1% |