Skip to content
Stacked Bar

Stacked Bar

A stacked bar chart.

Stacked Bar

Usage

from dataviz_mojo import stacked_bar
from dataviz_mojo.plot import save

def main() raises:
    var quarters: List[String] = ["Q1", "Q2", "Q3", "Q4"]
    var series_names: List[String] = ["North", "South", "East"]
    var values: List[List[Float64]] = [
        [42.0, 48.0, 45.0, 61.0],
        [30.0, 35.0, 33.0, 40.0],
        [55.0, 50.0, 58.0, 66.0],
    ]

    var c = stacked_bar(
        quarters,
        series_names,
        values,
        title="Quarterly Revenue by Region (stacked)",
        x_title="Quarter",
        y_title="Revenue ($M)",
    )
    save(c, "docs/src/examples/out_stacked_bar.svg")

Args:

  • categories: One stacked bar per entry, in the given order.
  • series_names: One stacked segment per name, used as the legend key.
  • values: values[j] is series_names[j]’s value per category.
  • theme: Full styling knobs beyond this function’s own parameters (colors, margins, fonts, gridlines, …) – see Theme’s docstring.
  • width: Pixel width of the returned Plot (.size()).
  • height: Pixel height of the returned Plot (.size()).
  • title: The chart’s title, shown above the plot.
  • subtitle: A secondary line shown under the title.
  • x_title: The x-axis caption.
  • y_title: The y-axis caption.