Zum Hauptinhalt springen

PieChart

Every example on this page is live, drawn by the library's Storybook, where you can also change its props and see the result.

Slices of a whole, each filled with a pattern, with a legend naming every slice and its share.

The pie stays round in any box: it is drawn as large as the box holds and centered, in the widget and in its previews alike. The legend sits around it and wraps or stacks to fit the room left. Negative values take no share of the pie, and a chart with no value above zero draws nothing.

Import​

import { PieChart } from "~lib/charts/pie-chart";

Props​

NameTypeRequiredDefaultDescription
data{ label: string; value: number; pattern?: PatternType }[]YesN/ASlice data
showLegendbooleanNotrueShow a legend naming each slice and its share
legendPosition"bottom" | "right" | "top" | "left"No"bottom"Where the legend sits around the pie
widthnumber | stringNo300Chart width
heightnumber | stringNo300Chart height

PatternType: "solid" | "diagonal" | "dots" | "crosshatch" — patterns cycle automatically if not specified.

Examples​

Simple​

Simple in Storybook öffnen

With Explicit Patterns​

With Patterns in Storybook öffnen

Without Legend​

No Legend in Storybook öffnen

Small Size​

Small Size in Storybook öffnen

Legend Beside a Wide Pie​

Wide With Legend Right in Storybook öffnen

See Also​