In order to use this kit, 'highcharts' and 'highcharts-react-official' must be installed in your repo.
This kit is a wrapper around the Highcharts library. It applies styling and default settings but does NOT ship Highcharts. Once 'highcharts' and 'highcharts-react-official are installed into your repo, any prop or functionality provided by Highcharts can be used with this kit without requiring specific props from Playbook. The doc examples below showcase a few common usecases but are not a comprehensive list of all the functionalities possible.
See the highcharts API docs for a comprehensive look at what is possible.
In order to use this kit, 'highcharts' and 'highcharts-react-official' must be installed in your repo.
<% chart_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] }] %> <% chart_options = { series: chart_data, title: { text: 'Solar Employment Growth by Sector, 2010-2016', }, subtitle: { text: 'Source: thesolarfoundation.com', }, xAxis: { categories: ['Jan', 'Feb', 'Mar', 'Apr', 'May'], }, yAxis: { title: { text: 'Number of Employees', }, }, } %> <%= pb_rails("pb_bar_graph", props: {options: chart_options}) %>
<% chart_data = [{ name: 'Number of Installations', data: [1475,200,3000,654,656] }] %> <% chart_options = { series: chart_data, title: { text: 'Bar Graph with Legend', }, xAxis: { categories: ['Jan','Feb','Mar','Apr','May','Jun','Jul','Aug','Sep','Oct','Nov','Dec'], }, yAxis: { title: { text: 'Number of Employees', }, }, legend: { enabled: true }, } %> <%= pb_rails("pb_bar_graph", props: {options: chart_options}) %>
Highcharts provides many options for customizing the legend display. This example showcases the following:
align can be used to align the legend left, right or center (defaults to center)
verticalAlign can be used to place the legend above the graph. Options are top, middle, bottom with default set to bottom
layout determines the position of the legend items. Options are horizontal, vertical or proximate with default set to horizontal 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 alignment. Negative x moves it to the left, positive x moves it to the right (defaults to 0)
y offsets the legend relative to its vertical alignment. Negative y moves it up, positive y moves it down (defaults to 0)
<% chart_data = [{ name: 'Installation', data: [1475] }, { name: 'Manufacturing', data: [4434] }, { name: 'Sales & Distribution', data: [3387] }, { name: 'Project Development', data: [3227] }, { name: 'Other', data: [1111] }] %> <% chart_options_right = { series: chart_data, title: { text: 'Alignment of Legend', }, xAxis: { categories: ['Jan'], }, yAxis: { title: { text: 'Number of Employees', }, }, legend: { enabled: true, align: 'right', verticalAlign: 'top', }, } %> <%= pb_rails("title", props: {size: 4, text: "align | verticalAlign", padding_top: "sm", padding_bottom: "sm"})%> <%= pb_rails("pb_bar_graph", props: {options: chart_options_right}) %> <% chart_options_center = { series: chart_data, title: { text: 'Layout of Legend', }, xAxis: { categories: ['Jan'], }, yAxis: { title: { text: 'Number of Employees', }, }, legend: { enabled: true, align: 'center', verticalAlign: 'bottom', layout: 'vertical', }, } %> <%= pb_rails("title", props: {size: 4, text: "layout", padding_top: "sm", padding_bottom: "sm"})%> <%= pb_rails("pb_bar_graph", props: {options: chart_options_center}) %> <% chart_options_left = { series: chart_data, title: { text: 'Offset of Legend', }, xAxis: { categories: ['Jan'], }, yAxis: { title: { text: 'Number of Employees', }, }, legend: { enabled: true, align: 'center', verticalAlign: 'bottom', layout: 'vertical', x: 100, y: 10, }, } %> <%= pb_rails("title", props: {size: 4, text: "x | y", padding_top: "sm", padding_bottom: "sm"})%> <%= pb_rails("pb_bar_graph", props: {options: chart_options_left}) %>
By default, Highcharts have a height of 400px, but this can be customized. You can override the default by specifying either a percentage or a fixed pixel value.
Using a percentage maintains a consistent aspect ratio across different responsive sizes. For example, setting the height to 50% makes the chart’s height half of its width.
<% chart_data = [{ name: 'Number of Installations', data: [1475,200,3000,654,656] }] %> <% chart_options_pixel = { chart: { height: "300" }, series: chart_data, title: { text: "Fixed Height (300px)", }, xAxis: { categories: ["Jan", "Feb", "Mar", "Apr", "May"], }, yAxis: { title: { text: "Number of Employees", }, } } %> <%= pb_rails("pb_bar_graph", props: {options: chart_options_pixel}) %> <br /><br /> <% chart_options_percentage = { chart: { height: "50%" }, series: chart_data, title: { text: "Percentage Height (50%)", }, xAxis: { categories: ["Jan", "Feb", "Mar", "Apr", "May"], }, yAxis: { title: { text: "Number of Employees", }, } } %> <%= pb_rails("pb_bar_graph", props: {options: chart_options_percentage}) %>
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.
<% chart_data = [{ name: 'Number of Installations', data: [1475,200,3000,654,656] }, { type: 'spline', name: 'Trend Line', data: [1975, 600, 2500, 924, 500], color: '#F9BB00', }] %> <% chart_options = { series: chart_data, title: { text: 'Bar Graph with Spline', }, subtitle: { text: 'Source: thesolarfoundation.com', }, xAxis: { categories: ['Jan', 'Feb', 'Mar', 'Apr', 'May'], }, yAxis: { title: { text: 'Number of Employees', }, }, legend: { enabled: true }, } %> <%= pb_rails("pb_bar_graph", props: {options: chart_options}) %>
Custom data colors allow for color customization to match the needs of business requirements. To accomplish this, you can use hex values.
<% chart_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] }] %> <% chart_options = { series: chart_data, title: { text: "Bar Graph with Custom Data Colors", }, xAxis: { categories: ["Jan", "Feb", "Mar", "Apr", "May"], }, yAxis: { title: { text: "Number of Employees", }, }, colors: ['#1CA05C', '#FD804C', '#144075', '#00C4D7', '#DA0014'], } %> <%= pb_rails("pb_bar_graph", props: {options: chart_options}) %>
<% chart_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], }] %> <% chart_options = { series: chart_data, title: { text: "Bar Graph with Stacked Columns", }, xAxis: { categories: ["Jan", "Feb", "Mar", "Apr", "May"], }, yAxis: { title: { text: "Number of Employees", }, }, plotOptions: { column: { stacking: 'normal', borderWidth: 0, } }, legend: { enabled: true }, } %> <%= pb_rails("pb_bar_graph", props: {options: chart_options}) %>
<% chart_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 }] %> <% chart_options = { series: chart_data, title: { text: "Bar Graph with Negative Numbers", }, xAxis: { categories: ["Jan", "Feb", "Mar", "Apr", "May"], }, yAxis: { title: { text: "Number of Employees", }, }, legend: { enabled: true }, } %> <%= pb_rails("pb_bar_graph", props: {options: chart_options}) %>
<% chart_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 }] %> <% chart_options = { series: chart_data, title: { text: "Bar Graph with Secondary Y-axis", }, xAxis: { categories: ["Jan", "Feb", "Mar", "Apr", "May"], }, yAxis: [{ format: "{value}%", labels: { style: { fontFamily: "Power Centra", color: "#C1CDD6", fontWeight: "bold", fontSize: "12px", }, }, title: { text: "Number of Employees", style: { fontFamily: "Power Centra", color: "#C1CDD6", fontWeight: "bold", fontSize: "12px", }, }, }, { labels: { style: { fontFamily: "Power Centra", color: "#C1CDD6", fontWeight: "bold", fontSize: "12px", }, }, title: { text: "Percentage", style: { fontFamily: "Power Centra", color: "#C1CDD6", fontWeight: "bold", fontSize: "12px", }, }, opposite: true, min: 0, max: 100 }], legend: { enabled: true }, } %> <%= pb_rails("pb_bar_graph", props: {options: chart_options}) %>
<% chart_options = { 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: { title: { text: '', }, }, 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("pb_bar_graph", props: {options: chart_options}) %>
| Props | Type | Values |
|---|---|---|
gap |
array
|
none
xxs
xs
sm
md
lg
xl
|
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
max
|
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
grid
|
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
|
vertical_align |
array
|
baseline
super
top
middle
bottom
sub
text-top
text-bottom
|
height |
array
|
auto
xs
sm
md
lg
xl
xxl
xxxl
|
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
|
|
column_gap |
string
|
|
row_gap |
string
|
|
group_hover |
boolean
|
|
id |
string
|
|
data |
hashprop
|
|
aria |
hashprop
|
|
html_options |
hashprop
|
|
children |
proc
|
|
style |
hashprop
|
| Props | Type | Values | Default |
|---|---|---|---|
options |
string
|