Vega-Lite Stacked Bar

A vertical stacked bar chart showing department spend by month — the default `bar` mark in Vega-Lite stacks automatically when the same `x` value has multiple series, with no extra config beyond a `color` channel. The `stack` keyword on the y-encoding can switch between `'zero'`,

Template details

  • chart
  • bar
  • stacked
  • categorical
  • vega
  • vega-lite

When to use this template

A stacked bar chart reveals the composition of a total across different categories or over time. It helps an analyst understand how individual components contribute to an overall value and how those contributions change, making it ideal for tracking part-to-whole relationships and identifying shifts in proportions.

  • One quantitative measure (e.g., count, sum, duration).
  • One primary categorical or ordinal axis (e.g., time, region).
  • One secondary categorical dimension for stacking.
  • Data where the sum of stacked segments has meaning.
  • Tracking changes in composition or proportion over time.
  • Datasets with 2-7 distinct categories for stacking.

Browse all Koan templates