# Stacked 100%

> Compare how several wholes divide into parts by scaling every bar or column to the same length with stack "normalize", for categories or periods.

A 100% stacked chart scales every bar or column to the same length, so each one shows only how its total divides. The reader compares shares across groups, such as income brackets or years, even when the totals differ widely.

Use [grouped or stacked bars](/docs/comparison/grouped-stacked/) when the totals matter and the reader should still see them. Use a [pie or donut](/docs/part-to-whole/pie-donut/) for the shares of a single whole, and a [stacked area](/docs/change-over-time/stacked-area/) for the same normalized view drawn as a continuous shape over time.

## Normalized bars

Put `stack: "normalize"` on the quantitative channel of a bar chart. Each category's values scale to a fraction of its total, so every bar ends at the same place. The axis format `".0%"` prints the fractions as percentages. With `normalize`, value labels on the segments show each segment's share of the stack.

```json
{
  "mark": "bar",
  "data": [
    {
      "bracket": "Under $30K",
      "pct": 40,
      "category": "Housing"
    },
    {
      "bracket": "Under $30K",
      "pct": 18,
      "category": "Food"
    },
    {
      "bracket": "Under $30K",
      "pct": 15,
      "category": "Transport"
    },
    {
      "bracket": "Under $30K",
      "pct": 12,
      "category": "Healthcare"
    },
    {
      "bracket": "Under $30K",
      "pct": 15,
      "category": "Other"
    },
    {
      "bracket": "$30K - $50K",
      "pct": 35,
      "category": "Housing"
    },
    {
      "bracket": "$30K - $50K",
      "pct": 16,
      "category": "Food"
    },
    {
      "bracket": "$30K - $50K",
      "pct": 18,
      "category": "Transport"
    },
    {
      "bracket": "$30K - $50K",
      "pct": 10,
      "category": "Healthcare"
    },
    {
      "bracket": "$30K - $50K",
      "pct": 21,
      "category": "Other"
    },
    {
      "bracket": "$50K - $80K",
      "pct": 32,
      "category": "Housing"
    },
    {
      "bracket": "$50K - $80K",
      "pct": 14,
      "category": "Food"
    },
    {
      "bracket": "$50K - $80K",
      "pct": 19,
      "category": "Transport"
    },
    {
      "bracket": "$50K - $80K",
      "pct": 9,
      "category": "Healthcare"
    },
    {
      "bracket": "$50K - $80K",
      "pct": 26,
      "category": "Other"
    },
    {
      "bracket": "$80K - $120K",
      "pct": 30,
      "category": "Housing"
    },
    {
      "bracket": "$80K - $120K",
      "pct": 12,
      "category": "Food"
    },
    {
      "bracket": "$80K - $120K",
      "pct": 17,
      "category": "Transport"
    },
    {
      "bracket": "$80K - $120K",
      "pct": 8,
      "category": "Healthcare"
    },
    {
      "bracket": "$80K - $120K",
      "pct": 33,
      "category": "Other"
    },
    {
      "bracket": "Over $120K",
      "pct": 27,
      "category": "Housing"
    },
    {
      "bracket": "Over $120K",
      "pct": 10,
      "category": "Food"
    },
    {
      "bracket": "Over $120K",
      "pct": 14,
      "category": "Transport"
    },
    {
      "bracket": "Over $120K",
      "pct": 6,
      "category": "Healthcare"
    },
    {
      "bracket": "Over $120K",
      "pct": 43,
      "category": "Other"
    }
  ],
  "encoding": {
    "x": {
      "field": "pct",
      "type": "quantitative",
      "stack": "normalize",
      "axis": {
        "title": "Share of spending",
        "format": ".0%"
      }
    },
    "y": {
      "field": "bracket",
      "type": "nominal"
    },
    "color": {
      "field": "category",
      "type": "nominal"
    }
  },
  "chrome": {
    "title": "Lower-income households spend a larger share on housing",
    "subtitle": "Share of annual household expenditure by category and income bracket, 2022"
  }
}
```

## Normalized columns

Swap the channels, with the category on `x` and the number on `y`, and the bars become columns. Columns suit categories that are periods, such as years. The raw values here are gigawatts, and the chart shows only the share each source contributes in each year.

```json
{
  "mark": "bar",
  "data": [
    {
      "year": "2019",
      "capacity": 98,
      "type": "Solar"
    },
    {
      "year": "2019",
      "capacity": 58,
      "type": "Wind"
    },
    {
      "year": "2019",
      "capacity": 12,
      "type": "Hydro"
    },
    {
      "year": "2020",
      "capacity": 127,
      "type": "Solar"
    },
    {
      "year": "2020",
      "capacity": 90,
      "type": "Wind"
    },
    {
      "year": "2020",
      "capacity": 20,
      "type": "Hydro"
    },
    {
      "year": "2021",
      "capacity": 167,
      "type": "Solar"
    },
    {
      "year": "2021",
      "capacity": 93,
      "type": "Wind"
    },
    {
      "year": "2021",
      "capacity": 15,
      "type": "Hydro"
    },
    {
      "year": "2022",
      "capacity": 222,
      "type": "Solar"
    },
    {
      "year": "2022",
      "capacity": 75,
      "type": "Wind"
    },
    {
      "year": "2022",
      "capacity": 22,
      "type": "Hydro"
    },
    {
      "year": "2023",
      "capacity": 346,
      "type": "Solar"
    },
    {
      "year": "2023",
      "capacity": 107,
      "type": "Wind"
    },
    {
      "year": "2023",
      "capacity": 24,
      "type": "Hydro"
    }
  ],
  "encoding": {
    "x": {
      "field": "year",
      "type": "nominal"
    },
    "y": {
      "field": "capacity",
      "type": "quantitative",
      "stack": "normalize",
      "axis": {
        "title": "Share of capacity added",
        "format": ".0%"
      }
    },
    "color": {
      "field": "type",
      "type": "nominal"
    }
  },
  "chrome": {
    "title": "Solar was more than half of new capacity in every year",
    "subtitle": "Global renewable capacity additions by source, 2019-2023 (share of gigawatts)"
  }
}
```

## Shares over time

The same spec works with many periods. Here twelve quarters of revenue by segment are normalized, so you can see the mix shift while the totals grow or shrink beneath it. `labels: { density: "none" }` leaves the segment labels off to keep a crowded chart readable.

```json
{
  "mark": "bar",
  "data": [
    {
      "quarter": "2022-Q1",
      "revenue": 19.82,
      "segment": "Services"
    },
    {
      "quarter": "2022-Q1",
      "revenue": 51.03,
      "segment": "Devices"
    },
    {
      "quarter": "2022-Q1",
      "revenue": 12.48,
      "segment": "Cloud"
    },
    {
      "quarter": "2022-Q2",
      "revenue": 19.6,
      "segment": "Services"
    },
    {
      "quarter": "2022-Q2",
      "revenue": 48.96,
      "segment": "Devices"
    },
    {
      "quarter": "2022-Q2",
      "revenue": 13.12,
      "segment": "Cloud"
    },
    {
      "quarter": "2022-Q3",
      "revenue": 19.19,
      "segment": "Services"
    },
    {
      "quarter": "2022-Q3",
      "revenue": 50.23,
      "segment": "Devices"
    },
    {
      "quarter": "2022-Q3",
      "revenue": 13.98,
      "segment": "Cloud"
    },
    {
      "quarter": "2022-Q4",
      "revenue": 20.77,
      "segment": "Services"
    },
    {
      "quarter": "2022-Q4",
      "revenue": 65.78,
      "segment": "Devices"
    },
    {
      "quarter": "2022-Q4",
      "revenue": 14.85,
      "segment": "Cloud"
    },
    {
      "quarter": "2023-Q1",
      "revenue": 20.91,
      "segment": "Services"
    },
    {
      "quarter": "2023-Q1",
      "revenue": 51.33,
      "segment": "Devices"
    },
    {
      "quarter": "2023-Q1",
      "revenue": 15.65,
      "segment": "Cloud"
    },
    {
      "quarter": "2023-Q2",
      "revenue": 21.21,
      "segment": "Services"
    },
    {
      "quarter": "2023-Q2",
      "revenue": 48.48,
      "segment": "Devices"
    },
    {
      "quarter": "2023-Q2",
      "revenue": 16.43,
      "segment": "Cloud"
    },
    {
      "quarter": "2023-Q3",
      "revenue": 22.31,
      "segment": "Services"
    },
    {
      "quarter": "2023-Q3",
      "revenue": 49.32,
      "segment": "Devices"
    },
    {
      "quarter": "2023-Q3",
      "revenue": 17.52,
      "segment": "Cloud"
    },
    {
      "quarter": "2023-Q4",
      "revenue": 23.12,
      "segment": "Services"
    },
    {
      "quarter": "2023-Q4",
      "revenue": 67.44,
      "segment": "Devices"
    },
    {
      "quarter": "2023-Q4",
      "revenue": 18.66,
      "segment": "Cloud"
    },
    {
      "quarter": "2024-Q1",
      "revenue": 23.87,
      "segment": "Services"
    },
    {
      "quarter": "2024-Q1",
      "revenue": 53.67,
      "segment": "Devices"
    },
    {
      "quarter": "2024-Q1",
      "revenue": 19.94,
      "segment": "Cloud"
    },
    {
      "quarter": "2024-Q2",
      "revenue": 24.21,
      "segment": "Services"
    },
    {
      "quarter": "2024-Q2",
      "revenue": 52.89,
      "segment": "Devices"
    },
    {
      "quarter": "2024-Q2",
      "revenue": 21.3,
      "segment": "Cloud"
    },
    {
      "quarter": "2024-Q3",
      "revenue": 25.03,
      "segment": "Services"
    },
    {
      "quarter": "2024-Q3",
      "revenue": 54.11,
      "segment": "Devices"
    },
    {
      "quarter": "2024-Q3",
      "revenue": 22.17,
      "segment": "Cloud"
    },
    {
      "quarter": "2024-Q4",
      "revenue": 26.34,
      "segment": "Services"
    },
    {
      "quarter": "2024-Q4",
      "revenue": 71.42,
      "segment": "Devices"
    },
    {
      "quarter": "2024-Q4",
      "revenue": 23.85,
      "segment": "Cloud"
    }
  ],
  "encoding": {
    "x": {
      "field": "quarter",
      "type": "ordinal"
    },
    "y": {
      "field": "revenue",
      "type": "quantitative",
      "stack": "normalize",
      "axis": {
        "title": "Share of revenue",
        "format": ".0%"
      }
    },
    "color": {
      "field": "segment",
      "type": "nominal"
    }
  },
  "labels": {
    "density": "none"
  },
  "chrome": {
    "title": "Devices take a bigger share in each fourth quarter",
    "subtitle": "Quarterly revenue by business segment, 2022-2024 (share of total)"
  }
}
```

## Fields that matter

| Field | What it does |
| --- | --- |
| `mark` | `"bar"`. Horizontal bars or vertical columns follow from which channel holds the number. |
| `stack` on the quantitative channel | `"normalize"` scales each stack to a fraction of its total. Other values are `"zero"`, `"center"` and `null`. |
| `encoding.color` | The part of the whole. One segment per value of this field. |
| `axis.format` | `".0%"` prints the normalized fractions as percentages. |
| `labels.density` | `"none"` hides segment labels. |

## Related

- [Grouped and stacked bars](/docs/comparison/grouped-stacked/) keep the totals visible.
- [Stacked area](/docs/change-over-time/stacked-area/) for normalized shares drawn as areas.
- [Pie and donut](/docs/part-to-whole/pie-donut/) for the shares of one whole.
- [Waffle](/docs/part-to-whole/waffle/) for shares as countable squares.
- [Marks reference](/docs/spec/marks/) lists the channels and options each mark type takes.
