Keyboard shortcuts

Press or to navigate between chapters

Press S or / to search in the book

Press ? to show this help

Press Esc to hide this help

Pie / donut chart

Categorical proportions of a whole — budget allocation, market share, traffic-source mix. Donut variant adds a centred hole.

Demo — Nightingale's mortality data, Crimean War 1854–55

The demo plots causes of British army mortality during the first winter of the Crimean War (April 1854 – March 1855): 83 % preventable disease, 8 % battle wounds, 9 % other. This is the dataset that became Florence Nightingale's famous polar-area "coxcomb" diagram — the chart that drove sanitary reform across military hospitals and made the case for hygiene-as-public-health.

Source: Florence Nightingale — Wikipedia

Public surface

use wisp_chart::polar::{Pie, Slice};
use wisp_chart::color::Color;

let pie = Pie::new(vec![
    Slice::new(45.0, "Organic",  Color::from_hex("#0072b2").unwrap()),
    Slice::new(25.0, "Paid",     Color::from_hex("#d55e00").unwrap()),
    Slice::new(15.0, "Social",   Color::from_hex("#009e73").unwrap()),
    Slice::new(10.0, "Referral", Color::from_hex("#cc79a7").unwrap()),
    Slice::new(5.0,  "Direct",   Color::from_hex("#f0e442").unwrap()),
]);
let g = pie.emit_graphics(&theme, Vec2::new(320.0, 320.0));

Donut variant

let donut = Pie::new(slices).hollow_ratio(0.5);

hollow_ratio is clamped to [0, 0.95]. 0.0 = pie. Common donut hole values are 0.40.6 (typical brand donuts) or 0.7+ (thin ring).

Layout

Info

Slices render in input order, winding CCW from the +x axis (3 o'clock). Each slice's angular span is value / total * 2π. The pie centre sits at the centre of viewport_px; outer radius is min(width, height) * 0.45.

Caveats

Warning

Pie charts are perceptually unreliable for comparing slices that aren't dramatically different in size — readers can't estimate angle ratios well. Prefer a bar chart when the ranking of values matters.