Powered by AppSignal & Oban Pro

Stacked Bar Chart

20_stacked_bar_chart.livemd

Stacked Bar Chart

Mix.install([
  {:plotly_ex, "~> 0.3"},
  {:kino, "~> 0.18"}
])

Section

Set layout.barmode: "stack" to stack multiple Bar traces on top of each other at each x category.

alias Plotly.{Figure, Bar}

Figure.new()
|> Figure.add_trace(Bar.new(x: ["giraffes", "orangutans", "monkeys"], y: [20, 14, 23], name: "SF Zoo"))
|> Figure.add_trace(Bar.new(x: ["giraffes", "orangutans", "monkeys"], y: [12, 18, 29], name: "LA Zoo"))
|> Figure.update_layout(barmode: "stack")
|> Plotly.show()