Donut

<o-donut> draws a donut chart from a JSON array.

Each item becomes an <o-arc> with a value, and Orbit stacks them one after another around the ring. Values are shares of their sum, or of total when you want a ring that is not full.

Attributes

AttributeDefaultWhat it does
data[]Segments: [{ value, color?, label? }]. Without a color, a segment takes the next one of the palette.
totalthe sumWhat a full ring is worth. With total="100" and values that add up to 70, 30% stays empty.
range / from360 / 0Arc span and start angle, in degrees.
label / unitText in the middle.
thickness3Band thickness in lanes.
gap1.5Space between segments, in percent of the widget width.
shapenoneSegment endings. rounded gives pill-shaped segments.
trackfaint grayColor of the ring behind the segments, seen in the gaps and in an empty part.
size200pxWidth of the widget.
glowoffA glow in each segment color.
format, decimals, currency, localeNumber format of segment titles and the accessible name; percent is the share of the total, through Intl.NumberFormat. See Shared options.
themedark, light or glass. Also inherited from an ok-theme-* class on a container. See Shared options.

Change data with the same number of items and the arcs are patched in place. A different count rebuilds the ring.

Styling

PropertyDefaultWhat it does
--ok-trackrgba(127,127,127,.12)Ring behind the segments.
--ok-hub-colorinheritsColor of the readout in the middle.
--ok-hub-bgnoneBackground of the hole in the middle.
--ok-hub-size1.4emFont size of the readout.
--ok-font-size8cqminBase font size, as a share of the widget. Text scales with it.

More examples

Rounded segments with wider gaps

A partial ring

45 + 25 out of a total of 100 leaves the last 30% of the 270° range empty.

Updating the data

Accessibility

The donut has role="img" and a name that lists every segment, such as “Rent: 52; Food: 28; Other: 20”. Give items a label so the list makes sense; each segment also shows it as a tooltip. Set aria-label to replace the generated name. When colors are close, add the numbers somewhere in text as well.