# PieChart Show how a total is distributed across categories. Choose a pie or donut with the same data and controls. [Interactive guide](/docs/components/piechart) · Forge 3.2.0 Use the API for your installed version. Run `npx --no-install wss3-forge api --json` inside the project. ## Implementation guidance ### When to use it Use PieChart for mutually exclusive categories that sum to a meaningful total. Choose its donut variant when a center opening helps the presentation. ### How to compose it Provide category labels and values. Use the legend and summary to explain the total and enable showTable when readers need all rows. ### What to verify Check that positive values form the distribution and that a zero reads as zero percent. Inspect a segment by keyboard and touch. ## Usage ```tsx import { PieChart } from 'wss3-forge' import type { PieChartDatum, PieChartProps } from 'wss3-forge' ``` - Use mutually exclusive categories that add up to a meaningful total. - A measured zero has a zero percent share. Only positive values contribute to the distribution. The optional data table also lists missing and invalid entries. - Choose the donut variant to open the center of the plot. Adjust innerRadiusRatio to set the size of the opening. - Use the legend and summary to explain the distribution. Use the arrow keys or tap a segment to read its value and share. Add showTable to include all rows. ```tsx ``` ## Runnable examples ### Acquisition pie with zero and missing values ```tsx import { PieChart } from 'wss3-forge' import type { PieChartDatum } from 'wss3-forge' const acquisition: PieChartDatum[] = [ { label: 'Search', value: 540 }, { label: 'Direct', value: 240 }, { label: 'Referral', value: 120 }, { label: 'Newsletter', value: 0 }, { label: 'Partner traffic', value: null }, ] export default function Example() { return () } ``` ### Shipment status donut ```tsx import { PieChart, Text } from 'wss3-forge' import type { PieChartDatum } from 'wss3-forge' const shipments: PieChartDatum[] = [ { label: 'Delivered', value: 150 }, { label: 'In transit', value: 40 }, { label: 'Awaiting dispatch', value: 10 }, ] export default function Example() { return (200} categoryLabel="Status" valueLabel="Shipments" />) } ``` ## Root package API ### PieChart Show how a total is distributed across categories. Choose a pie or donut with the same data and controls. Props type: `PieChartProps` - `data` — `readonly PieChartDatum[]` Labels, values and optional colors for the categories. - `variant?` — `'pie' | 'donut'` Default `'pie'`. Options `"pie"`, `"donut"`. Whether the distribution fills the center or surrounds an open center. - `innerRadiusRatio?` — `number` Default `0.62`. Donut hole as a fraction of the outside radius. - `centerContent?` — `ReactNode` Content centered inside the donut hole. - `legendPlacement?` — `'below' | 'beside'` Default `'below'`. Options `"below"`, `"beside"`. Place the legend below the chart or beside it when space permits. - `animated?` — `boolean` Default `false`. Animate the entrance unless reduced motion is requested. - `categoryLabel?` — `string` Default `'Category'`. - `valueLabel?` — `string` Default `'Value'`. Name of the original measure in the data table. - `unit?` — `string` - `formatValue?` — `(value: number) => string` Format the original measure in the readout and table. - `title` — `string` - `summary?` — `string` - `size?` — `number` - `showLegend?` — `boolean` - `showTooltip?` — `boolean` - `showTable?` — `boolean` Default `false`. Offer a disclosure with the source values. - `emptyLabel?` — `string` Default `'No positive values to display.'`. - `className?` — `string` - `style?` — `CSSProperties` ## Related types ```ts export interface PieChartDatum { label: string value: number | null | undefined color?: string } export interface PieChartProps extends RadialChartPresentation { data: readonly PieChartDatum[] variant?: 'pie' | 'donut' /** Donut hole as a fraction of the outside radius. */ innerRadiusRatio?: number /** Content centered inside the donut hole. */ centerContent?: ReactNode /** Place the legend below the chart or beside it when space permits. */ legendPlacement?: 'below' | 'beside' /** Animate the entrance unless reduced motion is requested. */ animated?: boolean categoryLabel?: string valueLabel?: string unit?: string formatValue?: (value: number) => string } ```