Axon 911 Frontend DocsAxon 911 Frontend Docs
Axon 911 Frontend Docs
    Loading navigation…
U
User
Switch to light mode
  1. Components
  2. Pie Chart
  3. API and Development

Pie Chart

API and Development

View SourceOpens in a new tabSubmit IssueOpens in a new tab
PropTypeDefault
labelLocalizedMessagerequired
descriptionLocalizedMessage-
slicesreadonly PieChartSlice[]required
cutout`${number}%`"0%"
sliceGapnumber (pixels)4
paletteChartPalette | readonly string[]Categorical
showLegendbooleanfalse
legendPositionChartLegendPositionTop
hiddenSlicesreadonly number[] (controlled)-
defaultHiddenSlicesreadonly number[][]
onHiddenSlicesChange(hiddenSlices, details) => void-
formatLegendEntry(entry: PieChartLegendEntry) => ChartTextlabel and share
showTooltipbooleantrue
formatTooltipTitle(index, label) => LocalizedMessage | DisplayValuethe slice label
formatTooltipRow(row: PieChartTooltipRow) => LocalizedMessage | DisplayValuevalue and share
formatValue(value: number) => LocalizedMessage | DisplayValuelocale decimal format
localestringruntime locale
className, id, refroot div-
PieChart forwards data-* attributes to the root. It takes no style, role, children or event handler.
PieChartSlice
FieldTypeDefault
labelLocalizedMessage | DisplayValuerequired
valuenumberrequired
colorCSS color or bare custom property namepalette color for the position
PieChartLegendEntry and PieChartTooltipRow
{ index, value, formattedValue, share, formattedShare, slice }. share is from 0 to 1; formattedShare is the locale's percentage, a whole number when it is whole and otherwise one decimal.
Exports
PieChart, ChartLegendPosition, ChartPalette and the types PieChartProps, PieChartSlice, PieChartCutout, PieChartLegendEntry, PieChartTooltipRow, PieChartSelection, ChartColor, ChartText and ChartPaletteInput, from @prepared911/ui/pie-chart. The root barrel exports the same names (the shared ones once).
Props
NameTypeDefaultDescription
labelLocalizedMessage—Accessible name of the chart. It names the plot and captions the data table that assistive technology reads. The chart paints no heading; render one beside it if the screen needs one.
slicesreadonly PieChartSlice[]—The slices, in the order callbacks report as index. They run clockwise from the top (mirrored in right-to-left).
classNamestring—Classes appended after the generated classes. Put overrides in @layer chroma.overrides.
cutout`${number}%`—Size of the hole as a share of the radius: "60%" is a donut, "0%" a full pie. Defaults to "0%".
defaultHiddenSlicesreadonly number[]—Initial hidden slice positions when uncontrolled.
descriptionLocalizedMessage—Longer description of the chart, read after its name: what it shows, or how to explore it with a keyboard.
formatLegendEntry((entry: PieChartLegendEntry) => ChartText)—Formats one legend entry, the whole text beside the swatch. Defaults to the slice label and its share, for example Fire (25%): a whole percentage when it is whole, otherwise one decimal, in the locale's own digits.
formatTooltipRow((row: PieChartLegendEntry) => ChartText)—Formats one tooltip row, the whole text beside the swatch. Defaults to the formatted value and the share.
formatTooltipTitle((index: number, label: ChartText) => ChartText)—Formats the tooltip heading from the slice position and its label. Defaults to the slice label.
formatValue((value: number) => ChartText)—Formats a value for axis ticks, end labels, tooltip rows and the data table. Defaults to the runtime locale's decimal format. Return toDisplayValue(...) for data, or a LocalizedMessage when the text carries a unit word.
hiddenSlicesreadonly number[]—Controlled list of hidden slice positions. Pair with onHiddenSlicesChange.
idstring—Id of the root element.
legendPositionChartLegendPosition—Legend edge. Defaults to {@link ChartLegendPosition.Top}.
localestring—BCP 47 locale for the default value format. Defaults to the runtime locale.
onHiddenSlicesChange((hiddenSlices: readonly number[], details: ChangeDetails<ChangeReason>) => void)—Called with the next list of hidden slice positions when a legend entry is pressed, before it applies. details.cancel() keeps the current list.
paletteChartPaletteInput—Series colors. Defaults to {@link ChartPalette.Categorical}. After the last color the order repeats.
refRef<HTMLDivElement>—Ref to the root element.
showLegendboolean—Paints a legend whose entries are buttons that show or hide a series or slice. Defaults to false.
showTooltipboolean—Shows the tooltip on hover and keyboard focus. Defaults to true.
sliceGapnumber—Gap between neighboring slices in pixels, at any chart size. 0 removes it. Defaults to 4.
Storybook
Interactive examples and edge cases for this component are in Storybook.
DefaultOpens in a new tab
Previous
Pie Chart / Usage
Next
Pie Chart / Accessibility
On this page
PieChartSlice
PieChartLegendEntry and PieChartTooltipRow
Exports
Props
Storybook