Skip to content

Horizontal bar chart ​

Single-series horizontal bar chart for long category labels and ranked bars.

bar-horizontal is the same encoding as a vertical bar chart turned on its side — categories run down the left, bars extend to the right. It honours sort, sortMode, valueLabels, and valueLabelPosition. The alias horizontal-bar is registered against the same renderer.

When to use ​

  • Category labels are long (country names, survey responses, product names)
  • Ranking displays — high-to-low from top to bottom reads intuitively
  • Mobile-friendly layouts — horizontal bars grow vertically, adapting to narrow screens

When NOT to use ​

  • Time-based data (the horizontal axis conventionally represents time — use line)
  • A handful of categories with short labels — bar-vertical is more compact

Example ​

bpc
chart bar-horizontal {
  title = "Japan leads in life expectancy while the US lags behind"
  description = "Selected countries, years (2023)"
  source = "World Bank"
  sourceUrl = "https://data.worldbank.org"
  note = "Figures are estimates and may differ from national statistics"
  sort = descending
  colors = "#59a14f"
  horizontalLabelPosition = off
  horizontalGridStyle = none

  colorize "United States" {
    color = "#e15759"
  }

  data {
    "Japan" = 84.8
    "Switzerland" = 83.8
    "Australia" = 83.5
    "Sweden" = 83.1
    "Canada" = 82.7
    "France" = 82.5
    "Germany" = 81.4
    "United Kingdom" = 81.2
    "United States" = 78.5
    "China" = 78.2
  }
}

Properties ​

Every property bar-horizontal 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
legendbooleantrue
legendPositionselect: top, bottom, left, righttop
directLabellingselect: "", auto, outside, insideauto
swapLabelValuebooleanfalse
barBackgroundbooleanfalse
barSeparatorsbooleanfalse
barGaptext60
connectedColumnsbooleanfalse
connectionsOpacitytext0.15
waterfallbooleanfalse
waterfallTotalbooleanfalse
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)
horizontalTickValuestext(unset)
valueLabelsbooleantrue
valueLabelPositionselect: auto, outside, insideauto
tooltipsbooleanfalse
crosshairbooleanfalse
crosshairDirectionselect: both, vertical, horizontalboth
crosshairStyleselect: solid, dashed, dotteddashed
crosshairColortext#999

Overlays ​

Overlays add reference marks on each bar: a value mark (one extra column) or a range band (two extra columns), such as a confidence interval or last year's value. Overlay columns are not bars, so they never add bars or change the category count. With waterfall, each overlay is drawn relative to the running total at the start of its step, so the marks follow the floating bars. By default (directLabelling = auto) overlays are labelled directly on the first bar; set directLabelling = "" to show a key instead.

Cues change the bars themselves. On a range overlay, muteIfCrosses = 0 fades every bar whose range includes zero. On a value overlay, aboveColor and belowColor color each bar by whether it reaches its mark, and add matching entries to the key. The cue entries go in the key even when overlay titles are labelled directly.

See overlay for the keys and an example.

From packages/lib/src/samples/nato-defence-spending.bpc. A value overlay marks the 2% guideline and colors each ally by whether it reaches it.

bpc
chart bar-horizontal {
  theme = "blueprint-bold"
  colorPalette = "BlueprintBold"
  title = "Every NATO ally but Slovenia expects to spend at least 2% of GDP on core defence in 2026"
  description = "Core defence expenditure as a share of real GDP, 2026 estimates, percent"
  source = "NATO, Defence Investment of NATO Countries (2014-2026), Table 3"
  sourceUrl = "https://www.nato.int/content/dam/nato/webready/documents/finance/def-exp-2026-en.pdf"
  note = "Figures are NATO estimates. Iceland has no armed forces and is not in NATO's tables. Slovenia's figure dates from before its new government's review of defence spending."
  sort = descending

  overlay "Target" {
    title = "2% guideline"
    aboveColor = "#2a9d8f"
    belowColor = "#e15759"
  }

  data {
    series = "Share of GDP","Target"
    "Lithuania" = 5.33,2
    "Estonia" = 5.10,2
    "Latvia" = 4.92,2
    "Poland" = 4.68,2
    "Greece" = 3.65,2
    "Denmark" = 3.49,2
    "Sweden" = 3.22,2
    "Norway" = 3.17,2
    "United States" = 3.17,2
    "Türkiye" = 2.85,2
    "Germany" = 2.69,2
    "Finland" = 2.65,2
    "Netherlands" = 2.58,2
    "United Kingdom" = 2.56,2
    "Romania" = 2.43,2
    "Bulgaria" = 2.22,2
    "France" = 2.22,2
    "Montenegro" = 2.17,2
    "Albania" = 2.15,2
    "Canada" = 2.13,2
    "Italy" = 2.10,2
    "Portugal" = 2.10,2
    "Hungary" = 2.09,2
    "North Macedonia" = 2.09,2
    "Croatia" = 2.03,2
    "Luxembourg" = 2.03,2
    "Slovak Republic" = 2.02,2
    "Czechia" = 2.01,2
    "Belgium" = 2.00,2
    "Spain" = 2.00,2
    "Slovenia" = 1.61,2
  }
}

Common pitfalls ​

  • Forgetting to sort — an unranked horizontal bar chart loses most of its power
  • Mixing the horizontal axis with time, which reads as a flipped line chart
  • Long labels still cause issues at very narrow widths; truncate or shorten before publishing
  • bar-vertical — when labels are short and you have room horizontally
  • bar-stacked — when each bar should break down into segments
  • bar-split — when values can be positive or negative

See also ​

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