shadcn.io is not affiliated with official shadcn/ui
Waffle Chart Stats Block for React
A ten by ten grid of a hundred squares for a polling tool, one square per percent of the votes, filled column by column from the foot in four tones, with a list of the answers that lifts its squares when you point at it.
Installation
Overview
A waffle chart for React with Base UI. The result of one poll as a grid of a hundred squares, one for each percent of the votes, in a hairline frame with a + on each corner. The squares fill each column from the bottom and then the next column, in four segments at 100, 60, 30 and 14% of your theme's text colour, one for each answer. At the end of a wide screen, under a header that names the winner ("Saved views won with 44% of the votes"), a list of the answers works as the legend and as the control: pointing at or focusing an answer lifts its squares and dims the rest, and pressing it keeps them lifted. On a phone the order is the header, the grid, then the list. The shares are rounded by the largest-remainder method so the four always add to 100, and every square, share and headline is computed from the vote counts. It's a CSS grid of a hundred span elements with no chart library. For poll results, survey answers and any breakdown of a whole into a few parts.
FAQ
How do I change the poll?
Edit QUESTION and ANSWERS at the top of the file: each answer is a name and its votes, biggest first. The total, the whole-percent shares, the square each answer starts at, the legend and the headline are computed from them. The tones are four solid mixes in TONES; keep the answers to four, or add a tone for each extra one.
How do the shares add up to exactly 100?
Each exact share is rounded down, and the points that are left over go to the answers with the largest remainders, so the shares and the squares always total 100 even when plain rounding would give 99 or 101. With the sample votes, 44.1, 30.1, 18.0 and 7.8 become 44, 30, 18 and 8.
What does pointing at an answer do?
Its squares lift by two pixels and the other answers' squares fade to a faint tint, so you can find an answer's squares in the grid at a glance. The list entries are real buttons: they respond to hover, to keyboard focus and to a press, which keeps the squares lifted until you press again or choose another answer. On touch screens a tap does the same. Reduced motion removes the lift's transition but keeps the highlight.
Is the waffle chart accessible?
The grid is one image whose name lists every answer and its percent, and the same numbers are in the list under it, with the votes behind each share, so nothing depends on seeing the squares. The list buttons have names and states (aria-pressed) and a visible focus ring. The squares are decorative and the tones are weights of the text colour, so the chart is readable in greyscale and in both themes.
Why do the squares fill from the bottom, column by column?
It's how waffle charts are usually read, like a glass filling up from the bottom, one column after another. The order is computed once from each square's row and column, so the biggest answer takes the first four columns plus a few squares of the fifth. The grid is a left-to-right box in every language, so the first answer always fills from the start.
Related
- Pro
Stacked Percentage Bar Stats
Parts of a wholeOne 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
Donut Breakdown Stats
Parts of a wholeA 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%.
- Pro
Pictograph Unit Stats
Parts of a wholeFifty person icons in ten columns for a community platform, 35 solid and 15 faint, where one icon stands for 1,000 members, inside a card in card with the active count above and a plain sentence below.
- Pro
Two-Ring Donut Stats
Parts of a wholeA headcount donut with two rings: the departments' groups inside and their teams outside, each team sitting in its own group's arc, with a nested legend whose shares add up at every level.
- Pro
Legend Filter Heatmap Stats
HeatmapsA twelve-week by seven-day commit heatmap whose five-step legend is a set of toggles: choosing a level keeps only those days at full strength, outlines the rest and counts the days.
- Pro
Treemap Stats
Parts of a wholeA treemap of eight folders for a cloud-storage tool, each box as big as its share of the disk, at weights from 100% to 9%, with every folder's size and share in a list under the map.