Skip to content
shadcn.io

shadcn.io is not affiliated with official shadcn/ui

Donut Breakdown Stats Block for React

A budgeting app's month of spending as a framed donut with its total rolling up in the middle, beside a legend of five buckets with amount and share, the shares adding up to exactly 100%.

Framework
UI library

Preview

Preview width

Installation

Part of Pro
Pro unlocks the code and one-line install of every Pro button and text effect, plus the MCP for your AI editor.
Have Pro already? Sign in to open it.Opens here as soon as you're Pro.

Overview

A donut breakdown for React with Base UI. A split: at the start a square, framed donut (a hairline frame with a + on each corner) of the month's spending, with the total in its middle, rolling up once; at the end a short header ("Housing took 45% of March", then one sentence that says how the month compares with the one before) and a legend of the five buckets as rows. Each row has a swatch, the bucket's name, its amount and its share. The arcs start at twelve o'clock, run clockwise, largest first, in five solid foreground weights (100, 65, 40, 20 and 10 percent) with a 2 px gap between neighbours, so the chart reads in any theme without a hue. The shares are rounded by the largest-remainder method and always add up to 100. It's drawn with SVG circles and a dash pattern, with the numbers as real text in a description list, and it needs no chart library. On a phone the header comes first, then the donut, then the legend.

FAQ

How do I change the buckets?

Edit BUCKETS at the top of the file: each bucket is a label and the dollars spent. Add or remove buckets (up to five weights are defined; add a sixth to WEIGHTS for more). The total, every share, every arc, the middle and the header's headline are computed from the list, and FEBRUARY is the month before, for the comparison in the header's sentence.

Why do the shares add up to exactly 100%?

sharesOf rounds every share down and then gives the spare percent points to the buckets with the largest remainders. Rounding each to the nearest whole number can total 99 or 101, which looks like a mistake beside a total. The legend uses these whole numbers; the arcs use the exact fractions.

Why are the segments shades of one colour?

Primary stays on a page's one main action, and chart hues change from preset to preset. The five arcs are the foreground at 100, 65, 40, 20 and 10 percent, mixed with the background into solid colours (never see-through), and the legend repeats each shade as a swatch. The meaning is never carried by colour alone: every arc has its name, amount and share in text beside it.

Is it accessible?

The legend is a description list (a term for the bucket, its amount and share as descriptions), so a screen reader reads every number. The drawing is hidden from assistive technology because the list says the same, and the figure's caption says how the arcs run. The total in the middle is real text; with reduced motion the arcs and the digits appear at once.

Does it work right to left?

The donut sits in a box that is kept left to right, because a chart's direction is its own: arcs always run clockwise from twelve o'clock. The legend and header follow the page direction, and amounts and percentages are wrapped in bdi elements so signs and units stay in reading order.

How does it fit on a phone?

The split becomes one column in reading order: header, donut (about 280 px square), legend. The legend rows keep their swatch, name, amount and share on one line down to 320 px, and nothing scrolls sideways.

  • Pro

    An ad-spend donut whose middle follows your choice: it shows the total until you press a channel, then that channel's spend and share while its arc lifts out of the ring.

  • Pro

    Donut Pill Legend Stats

    Parts of a whole

    A traffic-source donut over a row of pill toggles: switch a source off and its arc leaves the ring, the others grow to fill it, and the shares and the total in the middle are worked out again.

  • Pro

    A city's electricity mix as a framed donut with four callouts standing round it at twelve, three, six and nine o'clock, each joined to its arc by a thin leader line; on a phone, a two by two grid.

  • Pro

    Half Donut Card Stats

    Parts of a whole

    A team's weekly capacity as a 180-degree arc of four segments with the total in its foot and a four-cell legend band, with no needle: one whole, shared out.

  • Pro

    One thick bar of a consultancy's week split into four segments at four weights with labels inside the wide ones, and a band of four legend cells under it; pointing at or focusing a cell brackets its segment.

  • Pro

    Twelve weeks of support tickets stacked by priority in three foreground weights, with toggles that double as the legend: switch a priority off and the stack, the scale and every total re-read.