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 when the totals matter and the reader should still see them. Use a pie or donut for the shares of a single whole, and a 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.
{
"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"
},
// … 19 more rows; Copy includes them
],
"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"
}
}import { Chart } from "@opendata-ai/openchart-react";
import type { ChartSpec } from "@opendata-ai/openchart-core";
import "@opendata-ai/openchart-core/styles.css";
const data = [/* 25 rows; Copy includes them */];
const spec: ChartSpec = {
data,
"mark": "bar",
"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"
}
};
export function Example() {
return <Chart spec={spec} />;
}
<script setup lang="ts">
import { Chart } from "@opendata-ai/openchart-vue";
import type { ChartSpec } from "@opendata-ai/openchart-core";
import "@opendata-ai/openchart-core/styles.css";
const data = [/* 25 rows; Copy includes them */];
const spec: ChartSpec = {
data,
"mark": "bar",
"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"
}
};
</script>
<template>
<Chart :spec="spec" />
</template>
<script lang="ts">
import { Chart } from "@opendata-ai/openchart-svelte";
import type { ChartSpec } from "@opendata-ai/openchart-core";
import "@opendata-ai/openchart-core/styles.css";
const data = [/* 25 rows; Copy includes them */];
const spec: ChartSpec = {
data,
"mark": "bar",
"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"
}
};
</script>
<Chart {spec} />
import { createChart } from "@opendata-ai/openchart-vanilla";
import type { ChartSpec } from "@opendata-ai/openchart-core";
import "@opendata-ai/openchart-core/styles.css";
const data = [/* 25 rows; Copy includes them */];
const spec: ChartSpec = {
data,
"mark": "bar",
"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"
}
};
const container = document.getElementById("chart");
if (!container) throw new Error('Add <div id="chart"></div> to the page first.');
createChart(container, spec);
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.
{
"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"
},
// … 9 more rows; Copy includes them
],
"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)"
}
}import { Chart } from "@opendata-ai/openchart-react";
import type { ChartSpec } from "@opendata-ai/openchart-core";
import "@opendata-ai/openchart-core/styles.css";
const data = [/* 15 rows; Copy includes them */];
const spec: ChartSpec = {
data,
"mark": "bar",
"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)"
}
};
export function Example() {
return <Chart spec={spec} />;
}
<script setup lang="ts">
import { Chart } from "@opendata-ai/openchart-vue";
import type { ChartSpec } from "@opendata-ai/openchart-core";
import "@opendata-ai/openchart-core/styles.css";
const data = [/* 15 rows; Copy includes them */];
const spec: ChartSpec = {
data,
"mark": "bar",
"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)"
}
};
</script>
<template>
<Chart :spec="spec" />
</template>
<script lang="ts">
import { Chart } from "@opendata-ai/openchart-svelte";
import type { ChartSpec } from "@opendata-ai/openchart-core";
import "@opendata-ai/openchart-core/styles.css";
const data = [/* 15 rows; Copy includes them */];
const spec: ChartSpec = {
data,
"mark": "bar",
"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)"
}
};
</script>
<Chart {spec} />
import { createChart } from "@opendata-ai/openchart-vanilla";
import type { ChartSpec } from "@opendata-ai/openchart-core";
import "@opendata-ai/openchart-core/styles.css";
const data = [/* 15 rows; Copy includes them */];
const spec: ChartSpec = {
data,
"mark": "bar",
"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)"
}
};
const container = document.getElementById("chart");
if (!container) throw new Error('Add <div id="chart"></div> to the page first.');
createChart(container, spec);
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.
{
"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"
},
// … 30 more rows; Copy includes them
],
"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)"
}
}import { Chart } from "@opendata-ai/openchart-react";
import type { ChartSpec } from "@opendata-ai/openchart-core";
import "@opendata-ai/openchart-core/styles.css";
const data = [/* 36 rows; Copy includes them */];
const spec: ChartSpec = {
data,
"mark": "bar",
"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)"
}
};
export function Example() {
return <Chart spec={spec} />;
}
<script setup lang="ts">
import { Chart } from "@opendata-ai/openchart-vue";
import type { ChartSpec } from "@opendata-ai/openchart-core";
import "@opendata-ai/openchart-core/styles.css";
const data = [/* 36 rows; Copy includes them */];
const spec: ChartSpec = {
data,
"mark": "bar",
"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)"
}
};
</script>
<template>
<Chart :spec="spec" />
</template>
<script lang="ts">
import { Chart } from "@opendata-ai/openchart-svelte";
import type { ChartSpec } from "@opendata-ai/openchart-core";
import "@opendata-ai/openchart-core/styles.css";
const data = [/* 36 rows; Copy includes them */];
const spec: ChartSpec = {
data,
"mark": "bar",
"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)"
}
};
</script>
<Chart {spec} />
import { createChart } from "@opendata-ai/openchart-vanilla";
import type { ChartSpec } from "@opendata-ai/openchart-core";
import "@opendata-ai/openchart-core/styles.css";
const data = [/* 36 rows; Copy includes them */];
const spec: ChartSpec = {
data,
"mark": "bar",
"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)"
}
};
const container = document.getElementById("chart");
if (!container) throw new Error('Add <div id="chart"></div> to the page first.');
createChart(container, spec);
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 keep the totals visible.
- Stacked area for normalized shares drawn as areas.
- Pie and donut for the shares of one whole.
- Waffle for shares as countable squares.
- Marks reference lists the channels and options each mark type takes.