# Grouped bars

> Use grouped bars to compare two to four series within each item, side by side on one baseline.

- Data type: Values per item (`compare`)
- Free (MIT): install with `npx chartreuse add grouped-bars`, or registry item `/r/grouped-bars.json`
- Example: **China made more solar power in 2024 than the US, India and Germany combined** (Electricity generated from solar, wind and hydro, terawatt-hours (TWh), 2024)
- How to read it: Each group is a country and each colour a source; turn sources on or off with the chips below.
- Interactive: filter
- Phone: Adapts to mobile (Draws its own phone layout below 520px) · Video formats: 16:9 (best 16:9)

## Use it when
- 2 to 4 series measured in the same unit for each item
- comparing within each item matters as much as across items
- up to about 8 items

## Avoid it when
- the series add up to a meaningful total (use stacked bars)
- more than four series (use small multiples)
- many items, which makes the groups unreadable

## Fields (data.json)
- `country` (category): the group (a country here); hints.short can shorten long names under the bars
- `solar` (number, unit "TWh", format count): one bar in every group per number key, in the data's order; 2 to 4 series read best, up to 6 drawn (the rest are named in a note), any names. Here: solar electricity, TWh
- `wind` (number, unit "TWh", format count): wind electricity, TWh
- `hydro` (number, unit "TWh", format count): hydroelectricity, 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 or tap a bar to read its value and share
- a chip per series (Solar, Wind, Hydro) toggles it and rescales the axis
- Motion: Bars rise country by country; toggling a source slides the others to fill the gap and rescales smoothly.
- Sound: A chime on each toggle; a pop on hover. 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": "grouped-bars",
  "title": "China made more solar power in 2024 than the US, India and Germany combined",
  "subtitle": "Electricity generated from solar, wind and hydro, terawatt-hours (TWh), 2024",
  "data": "/charts/grouped-bars.data.json"
}
```

## Source
Energy dataset (solar_electricity, wind_electricity, hydro_electricity), from Ember and the Energy Institute, Our World in Data (CC BY 4.0), retrieved 2026-12-01: https://github.com/owid/energy-data

Live: /charts/grouped-bars · Manifest: /charts/grouped-bars.json · Tags: grouped bars, clustered bars, energy, solar, wind, hydro, electricity
