Searching Puzzle Pieces

Type to search Puzzle Pieces.

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.

11.4kSessions
  • Organic4.2k
  • Direct3.1k
  • Referral1.9k
  • Social1.4k
  • Email800
Traffic by source
LabelValuePercent
Organic4.2k36.8%
Direct3.1k27.2%
Referral1.9k16.7%
Social1.4k12.3%
Email8007%

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
Traffic by source
LabelValuePercent
Organic4.2k36.8%
Direct3.1k27.2%
Referral1.9k16.7%
Social1.4k12.3%
Email8007%

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.

18kUsers
  • United States5.2k
  • Germany3.1k
  • India2.6k
  • Brazil1.8k
  • Japan1.5k
  • France1.2k
  • Canada950
  • Other1.6k
Users by country
LabelValuePercent
United States5.2k28.9%
Germany3.1k17.2%
India2.6k14.5%
Brazil1.8k10%
Japan1.5k8.3%
France1.2k6.7%
Canada9505.3%
Other1.6k9.1%