Skip to content
OpenChart

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.

0%20%40%60%80%100%Share of spendingUnder $30K$30K - $50K$50K - $80K$80K - $120KOver $120K40%18%15%12%15%35%16%18%10%21%32%14%19%9%26%30%12%17%8%33%27%10%14%6%43%HousingFoodTransportHealthcareOtherLower-income households spend a larger shareon housingShare of annual household expenditure by category and income bracket, 20220%20%40%60%80%100%Share of spendingUnder $30K$30K - $50K$50K - $80K$80K - $120KOver $120K40%18%15%12%15%35%16%18%10%21%32%14%19%9%26%30%12%17%8%33%27%10%14%6%43%HousingFoodTransportHealthcareOtherLower-income households spend a larger shareon housingShare of annual household expenditure by category and income bracket, 2022
Household spending by income bracket. Source: Bureau of Labor Statistics, Consumer Expenditure Survey.
{
  "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.

201920202021202220230%20%40%60%80%100%Share of capacity added58%35%7%54%38%8%61%34%70%24%73%22%SolarWindHydroSolar was more than half of new capacity inevery yearGlobal renewable capacity additions by source, 2019-2023 (share of gigawatts)201920202021202220230%20%40%60%80%100%Share of capacity added58%35%7%54%38%8%61%34%70%24%73%22%SolarWindHydroSolar was more than half of new capacity inevery yearGlobal renewable capacity additions by source, 2019-2023 (share of gigawatts)
Renewable capacity added by source. Source: International Energy Agency.
{
  "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.

2022-Q12022-Q22022-Q32022-Q42023-Q12023-Q22023-Q32023-Q42024-Q12024-Q22024-Q32024-Q40%20%40%60%80%100%Share of revenueServicesDevicesCloudDevices take a bigger share in each fourthquarterQuarterly revenue by business segment, 2022-2024 (share of total)2022-Q12022-Q22022-Q32022-Q42023-Q12023-Q22023-Q32023-Q42024-Q12024-Q22024-Q32024-Q40%20%40%60%80%100%Share of revenueServicesDevicesCloudDevices take a bigger share in each fourthquarterQuarterly revenue by business segment, 2022-2024 (share of total)
Revenue mix by quarter. Source: Illustrative data.
{
  "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.