Keyboard shortcuts

Press or to navigate between chapters

Press S or / to search in the book

Press ? to show this help

Press Esc to hide this help


ax_bar (categories, values) — Function

Bar chart for labeled or numeric data. Use inside ax_draw2d.

Calling forms:

  • ax_bar(categories, values) — string category list + numeric value list
  • ax_bar(values) — just values (auto-numbered 1, 2, 3, …)

For multiple series, use different name options and bar_mode layout option.

Examples

/* Basic bar chart */
ax_draw2d(
  ax_bar(["Q1","Q2","Q3","Q4"], [100,150,120,180]),
  title="Quarterly Sales"
)$

/* Colored bars */
ax_draw2d(
  color="steelblue", ax_bar(["A","B","C"], [10,20,30]),
  title="Categories"
)$

/* Grouped bars (multiple series) */
ax_draw2d(
  name="2024", ax_bar(["Q1","Q2","Q3"], [100,150,120]),
  name="2025", ax_bar(["Q1","Q2","Q3"], [110,160,140]),
  bar_mode="group", title="Year Comparison"
)$

/* Stacked bars */
ax_draw2d(
  name="Product A", ax_bar(["Jan","Feb","Mar"], [30,40,35]),
  name="Product B", ax_bar(["Jan","Feb","Mar"], [20,25,30]),
  bar_mode="stack"
)$

Relevant Options

OptionDefaultDescription
colorautoBar fill color
bar_widthautoBar width (0–1 fraction)
nameautoLegend entry / series name
opacity1.0Bar opacity

Layout Options

OptionValuesDescription
bar_mode"group", "stack", "overlay"How multiple bar series are arranged

See also: ax_draw2d, ax_histogram