Bar graphs are used to compare data. Bar graphs are not typically used to show percentages. The default height of bar graph is 400px and can be changed. The default height is in pixel units, but can also use percentage string (percentage would be that of the width. For example, height:"50%"
would mean that the height is 50% of the width). This allows for preserving the aspect ratio across responsive sizes.
For more information, see: highcharts/chart.height.
<% data = [{ name: 'Installation', data: [1475,200,3000,654,656] }, { name: 'Manufacturing', data: [4434,524,2320,440,500] }, { name: 'Sales & Distribution', data: [3387,743,1344,434,440,] }, { name: 'Project Development', data: [3227,878,999,780,1000] }, { name: 'Other', data: [1111,677,3245,500,200] }] %> <%= pb_rails("bar_graph", props: { axis_title: 'Number of Employees', chart_data: data, id: "bar-default", y_axis_min: 0, x_axis_categories:['Jan','Feb','Mar','Apr','May','Jun','Jul','Aug','Sep','Oct','Nov','Dec'], subtitle: 'Source: thesolarfoundation.com', title: 'Solar Employment Growth by Sector, 2010-2016', }) %>
<% data = [{ name: 'Number of Installations', data: [1475,200,3000,654,656] }] %> <%= pb_rails("bar_graph", props: { axis_title: 'Number of Employees', chart_data: data, id: "bar-test-2", y_axis_min: 0, x_axis_categories:['Jan','Feb','Mar','Apr','May','Jun','Jul','Aug','Sep','Oct','Nov','Dec'], title: 'Bar Graph with Legend', legend: true, }) %>
align
Type: String | Values: left | center | right (defaults to center)
verticalAlign
Type: String | Values: top | middle | bottom (defaults middle)
layout
Type: String | Values: horizontal | vertical | proximate (defaults to horizontal)
x
Type: Number (defaults to 0)
y
Type: Number (defaults to 0)
layout
determines the position of the legend items
layout: proximate
will place the legend items as close as possible to the graphs they're representing. It will also determine whether to place the legend above/below or on the side of the plot area, if the legend is in a corner.
x
offsets the legend relative to its horizontal alignmnet. Negative x moves it to the left, positive x moves it to the right
y
offsets the legend relative to its vertical alignmnet. Negative y moves it up, positive y moves it down.
<% data = [{ name: 'Installation', data: [1475] }, { name: 'Manufacturing', data: [4434] }, { name: 'Sales & Distribution', data: [3387] }, { name: 'Project Development', data: [3227] }, { name: 'Other', data: [1111] }] %> <%= pb_rails("title", props: {size: 4, text: "align | vertical_align", padding_top: "sm", padding_bottom: "sm"})%> <%= pb_rails("bar_graph", props: { axis_title: 'Number of Employees', chart_data: data, id:"legend-position-bar", y_axis_min: 0, x_axis_categories:['Jan'], title: 'Alignment of Legend', legend: true, align: 'right', vertical_align: 'top', padding_bottom: "sm", }) %> <%= pb_rails("title", props: {size: 4, text: "layout", padding_top: "sm", padding_bottom: "sm"})%> <%= pb_rails("bar_graph", props: { axis_title: 'Number of Employees', chart_data: data, id:"legend-position-bar-1", y_axis_min: 0, x_axis_categories:['Jan'], title: 'Layout of Legend', legend: true, layout: 'vertical', padding_top: "sm", padding_bottom: "sm", }) %> <%= pb_rails("title", props: {size: 4, text: "x | y", padding_top: "sm", padding_bottom: "sm"})%> <%= pb_rails("bar_graph", props: { axis_title: 'Number of Employees', chart_data: data, id:"legend-position-bar-2", y_axis_min: 0, x_axis_categories:['Jan'], title: 'Offset of Legend', legend: true, layout: "vertical", x: 100, y: 10, padding_top: "sm", }) %>
<% data = [{ name: 'Number of Installations', data: [1475,200,3000,654,656] }] %> <%= pb_rails("bar_graph", props: { axis_title: 'Number of Employees', chart_data: data, id: "bar-test-3", y_axis_min: 0, x_axis_categories: ['Jan','Feb','Mar','Apr','May','Jun','Jul','Aug','Sep','Oct','Nov','Dec'], title: 'Bar Graph with Legend Non Clickable', legend: true, toggle_legend_click: false, }) %>
<% data = [{ name: 'Number of Installations', data: [1475,200,3000,654,656] }] %> <%= pb_rails("bar_graph", props: { axis_title: 'Number of Employees', chart_data: data, id: "bar-fixed-height", y_axis_min: 0, x_axis_categories:['Jan','Feb','Mar','Apr','May','Jun','Jul','Aug','Sep','Oct','Nov','Dec'], title: 'Fixed Height (300px)', height: '300' }) %> <br /><br /> <%= pb_rails("bar_graph", props: { axis_title: 'Number of Employees', chart_data: data, id: "bar-percentage-height", y_axis_min: 0, x_axis_categories:['Jan','Feb','Mar','Apr','May','Jun','Jul','Aug','Sep','Oct','Nov','Dec'], title: 'Percentage Height (50%)', height: '50%' }) %>
A spline can be added by including a separate chart data with the type: 'spline'
attribute.
A color can also be specified for the spline.
<% data = [{ name: 'Number of Installations', data: [1475,200,3000,654,656] }, { type: 'spline', name: 'Trend Line', data: [1975, 600, 2500, 924, 500], color: '#F9BB00', }] %> <%= pb_rails("bar_graph", props: { axis_title: 'Number of Employees', chart_data: data, id: "bar-spline", y_axis_min: 0, x_axis_categories:['Jan','Feb','Mar','Apr','May','Jun','Jul','Aug','Sep','Oct','Nov','Dec'], subtitle: 'Source: thesolarfoundation.com', title: 'Bar Graph with Spline', legend: true, }) %>
Custom data colors
allow for color customization to match the needs of business requirements.
Pass the prop colors and use desired values data-1 | data-2 | data-3 | data-4 | data-5 | data-6 | data-7 | data-8
in an array. Hex colors are also available eg: #CA0095
<% data = [{ name: 'Installation', data: [1475,200,3000,654,656] }, { name: 'Manufacturing', data: [4434,524,2320,440,500] }, { name: 'Sales & Distribution', data: [3387,743,1344,434,440,] }, { name: 'Project Development', data: [3227,878,999,780,1000] }, { name: 'Other', data: [1111,677,3245,500,200] }] %> <%= pb_rails("bar_graph", props: { axis_title: 'Number of Employees', chart_data: data, id: "bar-colors", y_axis_min: 0, x_axis_categories:['Jan','Feb','Mar','Apr','May','Jun','Jul','Aug','Sep','Oct','Nov','Dec'], title: 'Bar Graph with Custom Data Colors', colors: ['data-4', 'data-5', 'data-6', 'data-7', 'data-8'] }) %>
The custom_options
prop provides comprehensive access to additional Highcharts options that are not explicitly defined as props.
It's important to note that certain options may require specific script imports to function properly.
<% data = [{ name: 'Role', data: [0, 200, 300, 654, 656], }, { name: 'Company', data: [150, 524, 320, 440, 500], }] %> <% bar_graph_options = { customOptions: { yAxis: { tickInterval: 5, }, xAxis: { categories: [ raw(pb_rails("icon", props: { icon: "frown", color: "error", size: "2x" })), raw(pb_rails("icon", props: { icon: "frown", color: "warning", size: "2x" })), raw(pb_rails("icon", props: { icon: "frown-open", color: "neutral", size: "2x" })), raw(pb_rails("icon", props: { icon: "smile", color: "category_7", size: "2x" })), raw(pb_rails("icon", props: { icon: "smile-beam", color: "success", size: "2x" })) ], labels: { useHTML: true, sytle: { fontSize: '1.4em', }, y: 42, }, }, legend: { itemMarginTop: 62, }, } } %> <%= pb_rails("bar_graph", props: { chart_data: data, id: "bar-default", legend: true, title: 'Bar Graph with Custom Overrides', custom_options: bar_graph_options }) %>
The stacking
prop can be used for a stacked bar graph. The prop allows for normal
or percent
as options.
<% data = [{ name: 'Installation', data: [1475, 200, 3000, 654, 656], }, { name: 'Manufacturing', data: [1270, 800, 200, 454, 956], }, { name: 'Sales & Distribution', data: [975, 1600, 1500, 924, 500], }] %> <%= pb_rails("bar_graph", props: { axis_title: 'Number of Employees', chart_data: data, id: "bar-default", y_axis_min: 0, x_axis_categories:['Jan','Feb','Mar','Apr','May','Jun','Jul','Aug','Sep','Oct','Nov','Dec'], stacking: "normal", title: 'Bar Graph with Stacked Columns', legend: true, }) %>
<% data = [{ name: 'Installation', data: [-475, 400, -1000, 354, -856], threshold: 0 }, { name: 'Manufacturing', data: [1475, 200, 1000, 654, -656], threshold: 0 }, { name: 'Sales & Distribution', data: [1270, 100, -1200, 554, 756], threshold: 0 }] %> <%= pb_rails("bar_graph", props: { axis_title: 'Number of Employees', chart_data: data, id: "bar-default", x_axis_categories:['Jan','Feb','Mar','Apr','May','Jun','Jul','Aug','Sep','Oct','Nov','Dec'], title: 'Bar Graph with Negative Numbers', legend: true, }) %>
Optionally add a second yAxis to support secondary datasets (e.x., a spline) by passingyAxis: 1
to the second node of your chartData
array.
To customize the format and/or title of your secondary yAxis, pass your desired values as arrays through the axisFormat
and axisTitle
props, respectively.
<% data = [{ name: 'Number of Installations', data: [1475,200,3000,654,656] }, { type: 'spline', name: 'Percentage', data: [48, 70, 25, 55, 72], color: '#F9BB00', yAxis: 1 }] %> <% axis_titles = [{name: "Number of Installations"}, {name: "Percentage"}] %> <% axis_formats = [{format: ""}, {format: "{value}%"}] %> <%= pb_rails("bar_graph", props: { axis_format: axis_formats, axis_title: axis_titles, chart_data: data, id: "bar-spline", y_axis_min: 0, x_axis_categories:['Jan','Feb','Mar','Apr','May','Jun','Jul','Aug','Sep','Oct','Nov','Dec'], subtitle: 'Source: thesolarfoundation.com', title: 'Bar Graph with Secondary Y-axis', legend: true, }) %>
<% bar_graph_options = { customOptions: { chart: { type: 'bar' }, title: { text: 'Historic World Population by Region', align: 'left' }, subtitle: { text: 'Source: <a ' + 'href="https://en.wikipedia.org/wiki/List_of_continents_and_continental_subregions_by_population"' + 'target="_blank">Wikipedia.org</a>', align: 'left' }, xAxis: { categories: ['Africa', 'America', 'Asia', 'Europe'], lineWidth: 0 }, yAxis: { min: 0, title: { text: 'Population (millions)', align: 'high' }, labels: { overflow: 'justify' }, }, tooltip: { valueSuffix: ' millions' }, plotOptions: { bar: { dataLabels: { enabled: true }, groupPadding: 0.1 } }, series: [{ name: 'Year 1990', data: [631, 727, 3202, 721] }, { name: 'Year 2000', data: [814, 841, 3714, 726] }, { name: 'Year 2018', data: [1276, 1007, 4561, 746] }] } } %> <%= pb_rails("bar_graph", props: { id: "bar-horizontal", y_axis_min: 0, custom_options: bar_graph_options, }) %>
Props | Type | Values |
---|---|---|
max_width |
array
|
0%
xs
sm
md
lg
xl
xxl
0
none
100%
|
min_width |
array
|
0%
xs
sm
md
lg
xl
xxl
0
none
100%
|
width |
array
|
0%
xs
sm
md
lg
xl
xxl
0
none
100%
|
z_index |
array
|
1
2
3
4
5
6
7
8
9
10
|
number_spacing |
array
|
tabular
|
shadow |
array
|
none
deep
deeper
deepest
|
line_height |
array
|
tightest
tighter
tight
normal
loose
looser
loosest
|
display |
array
|
block
inline_block
inline
flex
inline_flex
none
|
cursor |
array
|
auto
default
none
contextMenu
help
pointer
progress
wait
cell
crosshair
text
verticalText
alias
copy
move
noDrop
notAllowed
grab
grabbing
eResize
nResize
neResize
nwResize
sResize
seResize
swResize
wResize
ewResize
nsResize
neswResize
nwseResize
colResize
rowResize
allScroll
zoomIn
zoomOut
|
flex_direction |
array
|
row
column
rowReverse
columnReverse
|
flex_wrap |
array
|
wrap
nowrap
wrapReverse
|
justify_content |
array
|
start
end
center
spaceBetween
spaceAround
spaceEvenly
|
justify_self |
array
|
auto
start
end
center
stretch
|
align_items |
array
|
flexStart
flexEnd
start
end
center
baseline
stretch
|
align_content |
array
|
start
end
center
spaceBetween
spaceAround
spaceEvenly
|
align_self |
array
|
auto
start
end
center
stretch
baseline
|
flex |
array
|
auto
initial
0
1
2
3
4
5
6
7
8
9
10
11
12
none
|
flex_grow |
array
|
1
0
|
flex_shrink |
array
|
1
0
|
order |
array
|
1
2
3
4
5
6
7
8
9
10
11
12
|
position |
array
|
relative
absolute
fixed
sticky
|
hover |
array
|
|
border_radius |
array
|
none
xs
sm
md
lg
xl
rounded
|
text_align |
array
|
start
end
left
right
center
justify
justify-all
match-parent
|
overflow |
array
|
visible
hidden
scroll
auto
|
truncate |
array
|
1
2
3
4
5
|
left |
array
|
0
xxs
xs
sm
md
lg
xl
auto
initial
inherit
|
top |
array
|
0
xxs
xs
sm
md
lg
xl
auto
initial
inherit
|
right |
array
|
0
xxs
xs
sm
md
lg
xl
auto
initial
inherit
|
bottom |
array
|
0
xxs
xs
sm
md
lg
xl
auto
initial
inherit
|
min_height |
array
|
auto
xs
sm
md
lg
xl
xxl
xxxl
|
max_height |
array
|
auto
xs
sm
md
lg
xl
xxl
xxxl
|
overflow_x |
array
|
visible
hidden
scroll
auto
|
overflow_y |
array
|
visible
hidden
scroll
auto
|
margin |
array
|
none
xxs
xs
sm
md
lg
xl
|
margin_bottom |
array
|
none
xxs
xs
sm
md
lg
xl
|
margin_left |
array
|
none
xxs
xs
sm
md
lg
xl
|
margin_right |
array
|
none
xxs
xs
sm
md
lg
xl
|
margin_top |
array
|
none
xxs
xs
sm
md
lg
xl
|
margin_x |
array
|
none
xxs
xs
sm
md
lg
xl
|
margin_y |
array
|
none
xxs
xs
sm
md
lg
xl
|
padding |
array
|
none
xxs
xs
sm
md
lg
xl
|
padding_bottom |
array
|
none
xxs
xs
sm
md
lg
xl
|
padding_left |
array
|
none
xxs
xs
sm
md
lg
xl
|
padding_right |
array
|
none
xxs
xs
sm
md
lg
xl
|
padding_top |
array
|
none
xxs
xs
sm
md
lg
xl
|
padding_x |
array
|
none
xxs
xs
sm
md
lg
xl
|
padding_y |
array
|
none
xxs
xs
sm
md
lg
xl
|
classname |
string
|
|
dark |
boolean
|
|
group_hover |
boolean
|
|
id |
string
|
|
data |
hashprop
|
|
aria |
hashprop
|
|
html_options |
hashprop
|
|
children |
proc
|
|
style |
hashprop
|
Props | Type | Values | Default |
---|---|---|---|
vertical_align |
enum
|
top
middle
bottom
|
bottom
|
height |
string
|
||
align |
enum
|
left
right
center
|
center
|
axis_title |
string
|
||
axis_format |
string
|
||
chart_data |
array
|
||
custom_options |
string
|
||
orientation |
enum
|
vertical
horizontal
|
vertical
|
point_start |
numeric
|
||
stacking |
string
|
||
subtitle |
string
|
||
title |
string
|
||
x_axis_categories |
array
|
||
y_axis_min |
numeric
|
||
y_axis_max |
numeric
|
||
legend |
boolean
|
false
|
|
toggle_legend_click |
boolean
|
true
|
|
colors |
array
|
||
layout |
enum
|
horizontal
vertical
proximate
|
horizontal
|
x |
numeric
|
||
y |
numeric
|