Block 261 of 297
Stacked Bar Chart
Break each category into up to four segments, shown as amounts or as a 100% share.
- Puck key
- StackedBarChartBlock
- Export
- stackedBarChartBlock
- React component
- <StackedBarChart />
- Path
- components/puck/stacked-bar-chart-block.tsx
- Dependencies
- None
- License
- MIT
About this block
When to use it, how to write for it, and what to change in the code.
What it's for
Horizontal bars, each split into up to four segments, shown either as amounts so bar lengths compare totals or as a 100% share so the mix inside each bar compares. The legend lists each segment's overall total or share. Labels sit above the bars, so long names stay readable in any card width. Values accept P1 data bindings.
- Funding mix by program: grants, gifts, events and earned revenue
- Survey responses split by agree, neutral and disagree
- Participants by age group across sites
Writing the content
- List Segment names once, comma-separated in stacking order; only the first four are used.
- Enter each bar's Segment values in the same order as the names. Blank counts as zero.
- Choose 100% share to compare proportions; each bar then shows the first segment's share beside its label, so put the segment you care about most first.
- Bars accept up to 16 entries.
Accessibility
- The chart has role="img" with a summary that reads every bar's segments as values or percentages.
- "View data table" shows each segment's value and share plus a total per bar in a real table (WCAG 1.3.1).
- The legend names each segment beside its swatch with its total, so segments can be matched by name as well as shade.
Customizing the code
- Segment colors are the SWATCH array: indigo-600, indigo-400, indigo-200 and neutral-400.
- Bar thickness is h-3 on the track, and segments are separated by gap-0.5.
Editor fields
What content editors see in the P1 sidebar when they select this block.
- Titletext
- Heading levelselect
- Subtitle or periodtext
- Segment namestext
- Barsarray
- Scaleradio
- Value prefixtext
- Value suffixtext
- Footnotetext