Static/vector categorical comparisons in vertical, horizontal, grouped, or stacked layouts.
Purpose
Compare and rank named values across discrete categories, including grouped and stacked totals.
Use when
Use when bar length makes difference, order, or contribution easy to scan; choose horizontal bars for longer category labels.
Avoid when
Avoid when the key task is showing continuous change, dense distributions, or precise point-to-point relationships.
Equivalent data
Exact labels, category tables, and reference evidence accompany treatments that require precise reading without color alone.
DefaultRendered example
Monthly rainfall and evaporation
Grouped monthly rainfall and evaporation values.
Usage Example
@bar.Bar(bar.Config{Label:"Monthly rainfall and evaporation",Title:"Bar Chart",Labels:[]string{"Jan","Feb","Mar","Apr","May","Jun","Jul","Aug","Sep","Oct","Nov","Dec"},Series:[]bar.Series{{Name:"Rainfall",Values:rainfall},{Name:"Evaporation",Values:evaporation},},Legend:bar.LegendOptions{Placement:bar.LegendPlacementEnd,Overlay:true},Width:600,Height:400,})
Thickness and group spacing
Compare automatic geometry, bars using 15% of each allotted slot, and grouped bars without an inter-series gap.
Rounded value-end caps work with exact labels at either the value end or category-axis start.
Rounded caps and value-label anchorsRendered example
Rounded bars with end value labels
Rounded value-end caps with exact labels anchored at the end.
Rounded bars with start value labels
Rounded value-end caps with exact labels anchored at the start.
Rounded caps and value-label anchors
tightGap:=0.02labels:=bar.DataLabelOptions{Show:true,Format:bar.ValueFormatHumanized}base:=bar.Config{Label:"Rounded bars with exact value labels",Labels:months,Series:[]bar.Series{{Name:"Rainfall",Values:rainfall,Labels:labels},{Name:"Evaporation",Values:evaporation,Labels:labels}},Geometry:bar.GeometryOptions{GapRatio:&tightGap,RoundedCaps:true},}start:=basestart.LabelPosition=bar.DataLabelPositionStart@bar.Bar(base)@bar.Bar(start)
Statistical reference annotations
Average lines and minimum/maximum points add context. Exact values and computed references remain adjacent without relying on color.
Statistical reference annotationsRendered example
Monthly rainfall and evaporation reference annotations
Monthly values with average lines and minimum and maximum reference points; adjacent evidence lists every value and computed reference.Exact values and reference annotations
Category
Rainfall
Evaporation
Jan
2
3
Feb
5
6
Mar
7
9
Apr
23
26
May
26
29
Jun
77
71
Jul
136
176
Aug
162
182
Sep
33
49
Oct
20
19
Nov
6
6
Dec
3
2
Series
Average
Maximum
Minimum
Rainfall
42
162 at Aug
2 at Jan
Evaporation
48
182 at Aug
2 at Dec
Statistical reference annotations
references:=bar.References{Average:true,Minimum:true,Maximum:true,Format:bar.ValueFormatHumanized,}@bar.Bar(bar.Config{Label:"Monthly rainfall and evaporation reference annotations",Labels:[]string{"Jan","Feb","Mar","Apr","May","Jun","Jul","Aug","Sep","Oct","Nov","Dec"},Series:[]bar.Series{{Name:"Rainfall",Values:rainfall,References:references},{Name:"Evaporation",Values:evaporation,References:references},},Width:600,Height:400,})
Stacked totals
Stacked bars preserve component contributions while a maximum line and global maximum point identify the largest total.
Stacked totalsRendered example
Stacked monthly rainfall and evaporation
Monthly totals retain each series contribution and the maximum stack total.Exact values and reference annotations
Category
Rainfall
Evaporation
Jan
2
3
Feb
5
6
Mar
7
9
Apr
23
26
May
26
29
Jun
77
71
Jul
136
176
Aug
162
182
Sep
33
49
Oct
20
19
Nov
6
6
Dec
3
2
Rainfall maximum line
162 at Aug
Maximum stack total
344 at Aug
Stacked totals
@bar.Bar(bar.Config{Label:"Stacked monthly rainfall and evaporation",Labels:months,Stacked:true,Series:[]bar.Series{{Name:"Rainfall",Values:rainfall,References:bar.References{MaximumLine:true,Format:bar.ValueFormatHumanized}},{Name:"Evaporation",Values:evaporation,References:bar.References{GlobalMaximum:true,PointPrefix:"Sum:",PointSize:32,Format:bar.ValueFormatHumanized}},},Padding:bar.Padding{Top:20,Right:45,Bottom:20,Left:20},})
Horizontal orientation
Use horizontal bars when category labels read more naturally beside values. Vertical remains the default.
Horizontal orientationRendered example
World population by reporting series
Population values reported for 2011 and 2012.Exact category values
Category
2011
2012
UN
10
20
Brazil
30
40
Indonesia
50
60
USA
70
80
India
90
100
China
110
120
World
130
140
Horizontal orientation
@bar.Bar(bar.Config{Label:"World population by reporting series",Title:"World Population",Orientation:bar.OrientationHorizontal,Labels:[]string{"UN","Brazil","Indonesia","USA","India","China","World"},Series:[]bar.Series{{Name:"2011",Values:[]float64{10,30,50,70,90,110,130}},{Name:"2012",Values:[]float64{20,40,60,80,100,120,140}},},Padding:bar.Padding{Top:20,Right:40,Bottom:20,Left:20},Width:600,Height:400,})
Horizontal thickness and group spacing
The same automatic, thin, and no-gap geometry options apply after changing orientation.
Horizontal thickness and group spacingRendered example
Default horizontal bar geometry
Automatic bar thickness and group spacing.Exact category values
Category
Rainfall
Evaporation
Jan
2
2.6
Feb
4.9
5.9
Mar
7
9
Apr
23.2
26.4
May
25.6
28.7
Jun
76.7
70.7
Thin horizontal bars
Each bar uses 15% of its allotted series slot.Exact category values
Category
Rainfall
Evaporation
Jan
2
2.6
Feb
4.9
5.9
Mar
7
9
Apr
23.2
26.4
May
25.6
28.7
Jun
76.7
70.7
No-gap horizontal bars
Grouped bars have no gap between series.Exact category values
Maximum reference lines remain aligned with the numeric axis after orientation changes.
Horizontal maximum referencesRendered example
Horizontal world population with maximum reference lines
Each reporting series includes its maximum-value reference line.Exact category values
Category
2011
2012
UN
10
20
Brazil
30
40
Indonesia
50
60
USA
70
80
India
90
100
China
110
120
World
130
140
Exact values and reference annotations
Category
2011
2012
UN
10
20
Brazil
30
40
Indonesia
50
60
USA
70
80
India
90
100
China
110
120
World
130
140
2011 maximum line
130 at World
2012 maximum line
140 at World
Horizontal maximum references
@bar.Bar(bar.Config{Label:"Horizontal world population with maximum reference lines",Orientation:bar.OrientationHorizontal,Labels:[]string{"UN","Brazil","Indonesia","USA","India","China","World"},Series:[]bar.Series{{Name:"2011",Values:values2011,References:bar.References{MaximumLine:true}},{Name:"2012",Values:values2012,References:bar.References{MaximumLine:true}},},})
Stacked horizontal values
Stacked horizontal bars can show exact segment labels and hide the redundant numeric axis.
Stacked horizontal valuesRendered example
Stacked horizontal values
Stacked 2011 and 2012 values with exact labels and a hidden numeric axis.Exact category values
Bar renders inline SVG on the server, supports SVG and PNG download through the shared wrapper, and remains useful in print or no-JavaScript output. Review the shared chart-mode and control guides for delivery and wrapper choices.
Go API
v0.0.1
The examples above cover behavior and composition. pkg.go.dev is the canonical reference for exported types, functions, methods, and Go documentation.
Goshtoso can store preferences and demo state in your browser. Some examples use cookies and IndexedDB to persist local demo state. There is no analytics, advertising, or third-party tracking. You can use the site without storage, but preferences and some examples will reset or stop persisting. Details in our Privacy Policy.