PieChart

A circle split into slices that show how a total divides between parts. Use it with few parts, up to five or six, where one slice is much bigger than the others.

Charts need Recharts. Install it once with yarn add recharts, then import from @bolio-ui/core/charts. The package stays out of your bundle until you use a chart.

General

Each item has a name and a value. The slices are sized against the sum of all values.

Legend and labels

Add withLegend to name the slices. withLabels writes a label on each one: its value, its name or its percent.

Colors and format

Set color on an item to override the theme color, and valueFormatter to change how a value reads.

Semicircle

Set startAngle and endAngle to draw only part of the circle. The chart still keeps the room of a full circle.

APIs

PieChart.Props

AttributeDescriptionTypeAccepted valuesDefault
dataone item per sliceChartSlice[]ChartSlice-
sizewidth and height of the ring, in pixelsnumber-220
withTooltipshow the value of a slice on hover and focusboolean-true
withLegendshow the legend below the chartboolean-false
withLabelswrite a label next to each sliceboolean-false
labelsTypewhat the labels saystring'value', 'name', 'percent'value
valueFormatterhow a value is written in the labels and the tooltip(value: number) => string-thousands separators, en-US
paddingAnglegap between the slices, in degreesnumber-0
startAnglewhere the first slice starts, in degreesnumber-90
endAnglewhere the last slice ends, in degreesnumber--270
...native props, passed to the rootHTMLAttributes'aria-label', 'className', ...-

ChartSlice

type ChartSlice = {
  name: string // shown in the legend, the tooltip and the name labels
  value: number // the size of the slice, against the sum of all values
  color?: string // any CSS color, a theme color when missing
}

Ref

The ref points at the root div.

Accessibility

Name the chart with aria-label, or with aria-labelledby pointing at a heading. A named chart becomes a group. The chart can be focused. Arrow Left and Right then move through the slices and show their values in the tooltip.

Color alone is a weak signal, so turn on withLegend or withLabels and write the key numbers in text next to the chart, or offer the same data in a Table.

Edit this page on GitHub