Skip to content
Horizontal Bar Chart

Horizontal Bar Chart

When to use

Horizontal bar charts work well when:

  • Category labels are long and would overlap on a vertical bar chart.
  • You are ranking items (leaderboard, top-N lists).
  • The natural reading direction for your categories is left-to-right.

Use ax.HBar(categories, values, chart.BarStyle{...}).


Basic example

package main

import (
	"github.com/goplotlib/goplotlib/chart"
	"github.com/goplotlib/goplotlib/plot"
)

func main() {
	cats := []string{"North America", "Europe", "Asia Pacific", "Latin America", "Middle East & Africa"}
	vals := []float64{84, 71, 63, 42, 29}

	fig := plot.New(plot.WithWidth(860), plot.WithHeight(420))
	ax := fig.AddAxes()
	ax.HBar(cats, vals, chart.BarStyle{Label: "revenue"})
	ax.SetTitle("Revenue by Region").SetXLabel("Revenue ($M)")
}

Horizontal bar chart


Style reference

chart.BarStyle fields (shared with Bar):

FieldTypeDefaultDescription
Labelstring""Series label shown in the legend
Colorcolor.ColorpaletteOverride the automatic palette color
Opacityfloat641.0Overall series opacity, 0.0–1.0
SquareBarsboolfalseSet true to disable the default rounded end caps