DonutChart

A ring split into slices, with room in the center for the total. It reads like a PieChart, and the hole gives you a place for the number that matters.

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

Same data as PieChart. Write the total in the middle with chartLabel.

Thickness

thickness sets the width of the ring, in pixels.

Legend and labels

Add withLegend to name the slices, and withLabels to write a value, name or percent on each one.

APIs

DonutChart.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
thicknesswidth of the ring, in pixelsnumber-24
chartLabeltext or number written in the centerstring / number--
...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