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.
NOTE: All chart kits are available through a separate entrypoint to keep Highcharts optional. Import them using:
import { PbGaugeChart } from 'playbook-ui/charts'
In order to use this kit, 'highcharts' and 'highcharts-react-official' must be installed in your repo.
Use custom CSS with classes or inline styles (as shown in these docs) to customize the appearance of prefix and suffix units.
<% data1 = [{ name: 'Data Used', y: 32 }] %> <% data2 = [{ name: 'Sales to Date', y: 65 }] %> <% chart_options_1 = { title: { text: "Data Usage", }, series: [{ data: data1 }], plotOptions: { solidgauge: { dataLabels: { format: '<span class="fix">{y:,f}</span>' + '<span style="fill: #687887; font-size: 27px;">GB</span>', }, }, }, } %> <% chart_options_2 = { title: { text: "Sales Goal", }, series: [{ data: data2 }], plotOptions: { solidgauge: { dataLabels: { format: '<span y="28" style="fill: #687887; font-size: 16px;">$</span>' + '<span class="fix" y="38">{y:,f}</span>' + '<span style="fill: #687887; font-size: 27px;">k</span>', }, }, }, } %> <%= pb_rails("pb_gauge_chart", props: { options: chart_options_1 }) %> <%= pb_rails("pb_gauge_chart", props: { options: chart_options_2 }) %>
<% data = [{ name: "Capacity", y: 75 }] %> <% chart_options = { title: { text: "Seating Capacity", }, series: [{ data: data }], pane: { startAngle: 0, endAngle: 360, }, plotOptions: { solidgauge: { dataLabels: { format: '<span class="fix">{y:,f}</span>' + '<span style="fill: #687887; font-size: 27px;">%</span>', }, }, }, } %> <%= pb_rails("pb_gauge_chart", props: { options: chart_options }) %>
By default, Highcharts set min to 0 and max to 100 but this can be customized if needed as shown here.
<% data = [{ name: "Rating", y: 4.5 }] %> <% chart_options = { title: { text: "Product Rating", }, yAxis: { min: 0, max: 5, lineWidth: 0, tickWidth: 0, minorTickInterval: nil, tickAmount: 2, tickPositions: [0, 5], labels: { y: 26, enabled: true, style: { color: '#C1CDD6', fontWeight:'700', } }, }, series: [{ data: data }], } %> <%= pb_rails("pb_gauge_chart", props: { options: chart_options }) %>
The Gauge chart resizes dynamically to fit whatever element it's placed within.
Note: set overflow to hidden on the parent element when nesting gauges inside of flex items to best respond to shrinking screens.
<% chart_options = { series: [{ data:[{ name: "Point 1", y: 100 }] }] } %> <% chart_options_1 = { series: [{ data:[{ name: "Point 2", y: 75 }] }] } %> <% chart_options_2 = { series: [{ data:[{ name: "Point 3", y: 50 }] }] } %> <% chart_options_3 = { series: [{ data:[{ name: "Point 4", y: 25 }] }] } %> <%= pb_rails("flex", props: {wrap: true, align: "center"}) do %> <%= pb_rails("flex/flex_item", props: {fixed_size: "400px", overflow: "hidden", shrink: true }) do %> <%= pb_rails("pb_gauge_chart", props: { options: chart_options }) %> <% end %> <%= pb_rails("flex/flex_item", props: {fixed_size: "300px", overflow: "hidden", shrink: true }) do %> <%= pb_rails("pb_gauge_chart", props: { options: chart_options_1 }) %> <% end %> <%= pb_rails("flex/flex_item", props: {fixed_size: "200px", overflow: "hidden", shrink: true }) do %> <%= pb_rails("pb_gauge_chart", props: { options: chart_options_2 }) %> <% end %> <%= pb_rails("flex/flex_item", props: {fixed_size: "155px", overflow: "hidden", shrink: true }) do %> <%= pb_rails("pb_gauge_chart", props: { options: chart_options_3 }) %> <% end %> <% end %>
<% chart_options = { title: { text: "Fixed Height in Pixels", }, chart: { height: "400", }, series: [{ data: [{ name: "Pixels", y: 400 }] }], plotOptions: { solidgauge: { dataLabels: { format: '<span class="fix">{y:,f}</span>' + '<span style="fill: #687887; font-size: 27px;">px</span>', }, }, }, } %> <% chart_options_1 = { title: { text: "Height as Percentage of Width", }, chart: { height: "45%", }, series: [{ data: [{ name: "Percentage", y: 45 }] }], plotOptions: { solidgauge: { dataLabels: { format: '<span class="fix">{y:,f}</span>' + '<span style="fill: #687887; font-size: 27px;">%</span>', }, }, }, } %> <%= pb_rails("pb_gauge_chart", props: { options: chart_options }) %> <%= pb_rails("pb_gauge_chart", props: { options: chart_options_1 }) %>
Highcharts allows for any custom colors to be used. Custom data colors allow for color customization to match the needs of business requirements.
For React, pass the option plotOptions.solidgauge.borderColor with a Playbook token like colors. + data_1 | data_2 | data_3 | data_4 | data_5 | data_6 | data_7 | data_8. HEX colors are also available eg: #CA0095
For Rails, the option plotOptions.solidgauge.borderColor can only be used with HEX values as shown.
We are able to wrap the Highcharts Gauge kit within Playbook kits (such as Flex and Card components).
<% chart_options = { series:[{data:[{ name: "Name", y: 10 }]}], chart: { height: "150", }, plotOptions: { series: { animation: false, }, solidgauge: { dataLabels: { format: '<span class="fix">{y:,f}</span>' + '<span style="fill: #687887; font-size: 27px;">%</span>', }, }, }, } %> <%= pb_rails("flex", props: {wrap: true, padding: "xl", gap: "sm"}) do %> <%= pb_rails("flex/flex_item", props: {flex: 1, grow: true }) do %> <%= pb_rails("card", props: {max_width: "xs", padding: "md", }) do %> <%= pb_rails("title", props: {padding_bottom: "sm", size: 4, text: "Abandoned Calls" })%> <%= pb_rails("flex", props: {align: "stretch"}) do %> <%= pb_rails("flex", props: {margin_right: "sm", orientation: "column"}) do %> <%= pb_rails("body", props: {color: "light", padding_bottom: "sm",text: "Total Abandoned"}) %> <%= pb_rails("flex", props: {align: "baseline", padding_bottom: "sx"}) do %> <%= pb_rails("title", props: {size: 1, text: "39"})%> <%= pb_rails("title", props: {color: "light", size: 3, text: "calls"}) %> <% end %> <%= pb_rails("caption", props: {size: "xs", text: "of 390" }) %> <%end %> <%= pb_rails("section_separator", props: {align_self: "stretch", margin_right: "sm", orientation: "vertical" }) %> <%= pb_rails("flex", props: {orientation: "column", wrap: true}) do %> <%= pb_rails("body", props: {color: "light", text: "% Abandoned"}) %> <%= pb_rails("flex", props: {wrap: true}) do %> <%= pb_rails("flex/flex_item", props: {fixed_size: "150px", overflow: "hidden", shrink: true}) do %> <%= pb_rails("pb_gauge_chart", props: { options: chart_options }) %> <% end %> <% end %> <% end %> <%end %> <% end %> <% end %> <% end %>
| Props | Type | Values |
|---|---|---|
align_content |
enum | responsive
|
start
end
center
spaceBetween
spaceAround
spaceEvenly
|
align_items |
enum | responsive
|
start
end
center
|
border_radius |
enum
|
none
xs
sm
md
lg
xl
rounded
|
cursor |
enum
|
auto
default
none
contextMenu
help
pointer
progress
wait
cell
|
dark |
boolean
|
true
false
|
flex |
enum | responsive
|
auto
initial
0
1
2
3
4
5
6
7
8
9
10
11
12
none
|
flex_direction |
enum | responsive
|
row
column
rowReverse
columnReverse
|
flex_wrap |
enum | responsive
|
wrap
nowrap
wrapReverse
|
justify_content |
enum | responsive
|
start
end
center
spaceBetween
spaceAround
spaceEvenly
|
line_height |
enum
|
loosest
looser
loose
normal
tight
tighter
tightest
|
margin_right |
array
|
none
xxs
xs
sm
md
lg
xl
|
margin_left |
array
|
none
xxs
xs
sm
md
lg
xl
|
margin_top |
array
|
none
xxs
xs
sm
md
lg
xl
|
margin_bottom |
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
|
margin |
array
|
none
xxs
xs
sm
md
lg
xl
|
width |
string
|
|
min_width |
string
|
|
max_width |
string
|
|
gap |
string | responsive
|
|
column_gap |
string | responsive
|
|
row_gap |
string | responsive
|
|
number_spacing |
enum
|
tabular
|
order |
enum | responsive
|
none
first
1
2
3
4
5
6
7
8
9
10
11
12
|
overflow_x |
enum
|
scroll
visible
hidden
auto
|
overflow_y |
enum
|
scroll
visible
hidden
auto
|
overflow |
enum
|
scroll
visible
hidden
auto
|
padding_right |
array
|
none
xxs
xs
sm
md
lg
xl
|
padding_left |
array
|
none
xxs
xs
sm
md
lg
xl
|
padding_top |
array
|
none
xxs
xs
sm
md
lg
xl
|
padding_bottom |
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
|
padding |
array
|
none
xxs
xs
sm
md
lg
xl
|
position |
enum
|
relative
absolute
fixed
sticky
static
|
shadow |
enum
|
none
deep
deeper
deepest
|
text_align |
enum | responsive
|
start
end
left
right
center
justify
justifyAll
matchParent
|
truncate |
enum
|
none
1
2
3
4
5
|
vertical_align |
enum | responsive
|
baseline
super
top
middle
bottom
sub
text-top
text-bottom
|
z_index |
enum | responsive
|
1
2
3
4
5
6
7
8
9
10
max
|
top |
enum | object
|
xxs
xs
sm
md
lg
xl
xxl
|
inset |
boolean
|
true
false
|
right |
enum | object
|
xxs
xs
sm
md
lg
xl
xxl
|
bottom |
enum | object
|
xxs
xs
sm
md
lg
xl
xxl
|
left |
enum | object
|
xxs
xs
sm
md
lg
xl
xxl
|
height |
string
|
|
max_height |
string
|
|
min_height |
string
|
|
hover |
object
|
|
group_hover |
boolean
|
true
false
|
| Props | Type | Values | Default |
|---|---|---|---|
options |
record<string, unknown>
|