# Stacked area

> Use a stacked area to show how a total and its parts change over time, when the parts add up to the whole.

- Data type: Values over time (`time`)
- Free (MIT): install with `npx chartreuse add stacked-area`, or registry item `/r/stacked-area.json`
- Example: **Wind and solar overtook hydropower in 2024 and now trail only coal and gas** (World electricity generation by source, terawatt-hours, 1985 to 2025)
- How to read it: Each band is one source; its thickness is that source's electricity and the top edge is the world total.
- Interactive: filter
- Phone: Adapts to mobile (Draws its own phone layout below 520px) · Video formats: 16:9 (best 16:9)

## Use it when
- parts add up to a meaningful total
- both the total and the mix matter
- 2 to 6 parts

## Avoid it when
- readers must compare the middle bands exactly (use lines or small multiples)
- parts don't add up
- more than six parts

## Fields (data.json)
- `year` (year): the year
- `coal` (number, unit "TWh", format count): electricity from coal, TWh
- `gas` (number, unit "TWh", format count): electricity from gas, TWh
- `nuclear` (number, unit "TWh", format count): electricity from nuclear, TWh
- `hydro` (number, unit "TWh", format count): electricity from hydropower, TWh
- `windSolar` (number, unit "TWh", format count): electricity from wind plus solar, TWh
- `other` (number, unit "TWh", format count): oil, bioenergy and other renewables, TWh

Units are the example's: with your own data, set each number field's `unit` and `format` (percent, count, decimal, currency, compact) in the meta you pass to mount, or `chartreuse render --unit field=text --format field=count`. Scales and labels follow your data.

## Interactions, motion, sound
- hover a band to read its value and share in any year
- the legend buttons switch sources off and on; the rest re-stack
- Motion: Bands rise from the baseline one after another, coal first; switching a source off re-stacks the rest smoothly.
- Sound: A pop when the hovered year changes, pitched by source; a whoosh when the stack re-forms. Quiet while it draws and between steps; mute it from its card. (sound is off until the viewer turns it on)

## Example spec
```json
{
  "chart": "stacked-area",
  "title": "Wind and solar overtook hydropower in 2024 and now trail only coal and gas",
  "subtitle": "World electricity generation by source, terawatt-hours, 1985 to 2025",
  "data": "/charts/stacked-area.data.json"
}
```

## Source
Electricity production by source, Our World in Data (Ember; Energy Institute Statistical Review of World Energy) (CC BY 4.0), retrieved 2026-12-01: https://ourworldindata.org/grapher/electricity-prod-source-stacked

Note: Wind and solar are summed into one band, and oil, bioenergy and other renewables into another, to keep six colours.

Live: /charts/stacked-area · Manifest: /charts/stacked-area.json · Tags: stacked area, parts over time, legend toggle, energy, electricity, climate
