Skip to content

Stacked bar ​

Stacked bars show composition within each category (absolute or normalised to 100%).

Identity ​

chartTypestackedBar · stackedBar100
Option bagbar
seriesData layoutseriesRows – row 0 = category header; later rows = series
Min grid2 rows × 2 columns (header included)
OrientationYes – vertical (default) or horizontal
SampleStacked bar · Percent axis

Minimal chartData ​

js
{
  chartType: 'stackedBar', // or 'stackedBar100'
  isDataTransposed: true,
  seriesData: [
    ['', 'Q1', 'Q2', 'Q3'],
    ['Product A', 40, 48, 52],
    ['Product B', 30, 28, 35],
  ],
  title: { visible: true, text: 'Mix by quarter' },
  subtitle: { visible: false, text: '' },
}

seriesData ​

Same seriesRows layout as clustered bar (isDataTransposed: true):

js
[
  ['', 'Q1', 'Q2', 'Q3'],
  ['Product A', 40, 48, 52],
  ['Product B', 30, 28, 35],
]

Shared layout rules: chartData schema · seriesData.


Option bag: bar ​

stackedBar / stackedBar100 / clusteredBar all read cd.bar. Stacking vs clustering comes from chartType, not a different bag.

FieldDefault (new charts)Role
padding0.3Gap between category stacks, 0–1
cornerRadius0Corner radius (px)
reverseStackOrderfalseReverse segment order within the stack
seriesStrokes / seriesStrokeWidths / seriesStrokeDashArrays[]Per-series stroke chrome
series / overridesemptyIndexed style patches
js
{
  chartType: 'stackedBar',
  seriesData: [/* … */],
  bar: {
    padding: 0.25,
    reverseStackOrder: true,
  },
}

Axes & scales ​

RoleVerticalHorizontal
Domainbottomleft
Primary rangeleftbottom

stackedBar ​

Absolute stacks. Keep 0 in range. Format and tick the primary range side after orientation.

stackedBar100 ​

Stacks normalised to 0–100. Defaults seed % postfix; prefer preferredTickInterval of 20 / 25 / 50 (divisors of 100).

js
{
  chartType: 'stackedBar100',
  isDataTransposed: true,
  seriesData: [/* … */],
  axes: {
    left: {
      labels: {
        preferredTickInterval: 25,
        // % postfix usually already seeded
      },
    },
  },
}

Details: Axes · by chart type · Value axis · percentage charts · Percent axis sample.


Type-specific behaviour ​

  • Switching stackedBar ↔ stackedBar100 ↔ clusteredBar keeps the same grid and bar bag.
  • Stack totals default on. Hide them with annotations.totals.visible: false – see Labels. Do not invent showTotalLabels.
  • Palette: legend.colors.

Pitfalls ​

  • Using the area bag on a stacked bar (foreign-option-bag)
  • Hand-picking a % tick interval that is not a divisor of 100 on stackedBar100
  • Pinning bounds that clip the stack (or that fight 0–100 on 100% charts)
  • Expecting reverseStackOrder to reorder categories – it reorders segments, not domain columns

Developer documentation for Chartbuddy Embed · Not the end-user Help Center · Help Center