Block 258 of 297
Stacked Area Chart
Two to four series stacked over time, with a legend of each series' latest value and the running total.
- Puck key
- StackedAreaChartBlock
- Export
- stackedAreaChartBlock
- React component
- <StackedAreaChart />
- Path
- components/puck/stacked-area-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
Up to four series stacked over shared x-axis labels, so the top edge traces the total and each band is one part of it. The legend leads with the latest total and each series' latest value, and a data table with a Total column sits behind a disclosure. The chart shortens and shows fewer x labels in a narrow card. Values accept P1 data bindings.
- Meals or services delivered per month, split by program
- Revenue by source over several years
- Visitors by channel, such as in person, online and mobile
Writing the content
- Enter Series (bottom to top) in stacking order; put the largest, steadiest series first so it sits on the baseline in the darkest shade.
- Give every series one value per X-axis label. Blanks and negatives count as zero, so this chart doesn't suit data that dips below zero.
- Use two to four series; for one, a Line Chart reads more clearly.
- Short suffixes like % show on the axis; longer ones like meals appear in the legend and table only.
Accessibility
- The chart area has role="img" with a summary giving the latest value for each series, the latest total and the range of the total.
- "View data table" opens a native details disclosure with a real table that includes a Total column (WCAG 1.3.1).
- Legend entries pair each swatch with the series name and value in a description list, so bands can be identified without relying on shade alone.
Customizing the code
- Band colors are in the STYLES array, darkest on the baseline; the top outline uses stroke-indigo-700.
- Chart height is CHART_HEIGHT, h-44 @md:h-56.
Editor fields
What content editors see in the P1 sidebar when they select this block.
- Titletext
- Heading levelselect
- Subtitle or periodtext
- X-axis labelstext
- Series (bottom to top)array
- Value prefixtext
- Value suffixtext
- Footnotetext