Skip to content

Stacked bar chart ​

Stacked horizontal bar chart for composition within a category, emphasising the total.

bar-stacked segments horizontal bars into subcategories, showing both the individual parts and the total. Set stackMode = "percent" to flip to a 100 % view for pure composition. See Properties for every key it accepts.

When to use ​

  • Showing how a total breaks down into parts
  • Comparing totals across categories while keeping the composition visible
  • 100 % stacked view (stackMode = "percent") when relative proportions matter more than absolute values
  • Categories with long labels that suit the horizontal orientation

When NOT to use ​

  • When comparing individual segments across categories — only the segment on the baseline is easy to read
  • When there are many small segments — they become invisible
  • When precise segment-to-segment comparison is needed (use bar-multi or bar-grouped)

Example ​

bpc
chart bar-stacked {
  theme = "blueprint-bold"
  colorPalette = "BlueprintBold"
  title = "India's working-age population now surpasses China's"
  description = "Millions of people, 2023"
  source = "UN Population Division"
  sourceUrl = "https://population.un.org"
  horizontalGridStyle = none
  horizontalLabelPosition = off

  data {
    series = "0-14","15-64","65+"
    "China" = 249,987,191
    "India" = 365,948,100
    "USA" = 60,215,58
    "Indonesia" = 66,191,18
    "Brazil" = 42,150,22
  }
}

Properties ​

Every property bar-stacked accepts, beside the frame and layout keys every chart shares. Anything absent from this table is rejected by validateChart and ignored by the renderer.

PropertyTypeDefault
colorscolors(unset)
colorPaletteselect, see PalettesBlueprint
autoContrastbooleanfalse
allowDarkModebooleantrue
stackModeselect: normal, percentnormal
sortModeselect: none, total, within-groupsnone
legendbooleantrue
legendAnchorselect: start, middle, endstart
legendPositionselect: top, bottom, left, righttop
directLabellingselect: "", auto, outside, inside""
directLabelAnchorselect: start, middle, endmiddle
categoryLabelLinebooleanfalse
showVerticalAxisbooleantrue
verticalAxisDirectionselect: left, rightleft
showVerticalTicksbooleanfalse
verticalLabelPositionselect: auto, inside, outside, offauto
verticalGridStyleselect: solid, dashed, dotted, nonenone
verticalNumberFormatnumberFormat(unset)
showHorizontalAxisbooleanfalse
showHorizontalTicksbooleanfalse
horizontalLabelPositionselect: auto, inside, outside, offoff
horizontalLabelRotationselect: auto, horizontal, verticalhorizontal
horizontalGridStyleselect: solid, dashed, dotted, nonenone
horizontalNumberFormatnumberFormat(unset)
horizontalScaleTypeselect: linear, loglinear
horizontalRangeMintext(unset)
horizontalRangeMaxtext(unset)
valueLabelsbooleantrue
valueLabelPositionselect: auto, outside, insideauto
tooltipsbooleanfalse
crosshairbooleanfalse
crosshairDirectionselect: both, vertical, horizontalboth
crosshairStyleselect: solid, dashed, dotteddashed
crosshairColortext#999

Common pitfalls ​

  • Segments not on the baseline are nearly impossible to compare accurately — put the most important segment first
  • Too many segments create visual noise without insight — cap at 3–5 and group the rest into "Other"
  • Inconsistent segment ordering across bars breaks the visual rhythm

See also ​

Released under the MIT License. Built static-first — your data never leaves the page.