Treemap charts are used to compare the relative size of groups of data. They can also use a nested data structure, allowing a user to drill down into a group to see its constituent data points.
The default height of treemap 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.
Points are automatically arranged by their value
size.
By default, point colors are assigned sequentially from the global data
colors. Note that data points without a value (such as parent nodes) will still take on the next available color.
<% data = [ { name: "Pepperoni", parent: "Toppings", value: 600, }, { name: "Cheese", parent: "Toppings", value: 510, }, { name: "Mushroom", parent: "Toppings", value: 330, },{ name: "Onions", parent: "Toppings", value: 250, }, { name: "Olives", parent: "Toppings", value: 204, }, { name: "Pineapple", parent: "Toppings", value: 90, }, { name: "Pizza Toppings", id: "Toppings", }, ] %> <%= pb_rails("treemap_chart", props: { chart_data: data, id: "treemap-default", title: "Favored Pizza Toppings", }) %>
Data can be grouped into distinct segments by specifying the relationship in the chartData
. For a point to be a parent, it needs an id
of type string
included in its object. Any other data points may then reference that id
as their parent
value to establish the tree structure.
Parents can also be passed a custom color to be applied to all of its child points.
<% data = [ { name: 'Meat', id: 'Meat', color: "#0056CF", }, { name: 'Pepperoni', parent: 'Meat', value: 250, }, { name: 'Meatball', parent: 'Meat', value: 400, }, { name: "Anchovy", parent: 'Meat', value: 40, }, { name: 'Vegetarian', id: 'Vegetarian', color: "#F9BB00", }, { name: 'Onions', parent: 'Vegetarian', value: 300, }, { name: 'Pineapple', parent: 'Vegetarian', value: 90, }, { name: "Peppers", parent: 'Vegetarian', value: 80, }, { name: "Specialty", id: "Specialty", color: "#9E64E9", },{ name: "Buffalo Chicken", parent: "Specialty", value: 400, }, { name: "Supreme", parent: "Specialty", value: 150, } ] %> <%= pb_rails("treemap_chart", props: { chart_data: data, grouped: true, id: "treemap-grouped", title: "Grouped Toppings", }) %>
Adding the drillable
prop allows the tree to be traversed up and down by clicking into each box. Relationships are established through the chartData
, detailed in the Grouped Data section above.
<% data = [ { name: "Evergreen", id: "Evergreen", color: "#0056CF", }, { name: "Pine", id: "Pine", parent: "Evergreen", value: 300, color: "#477BC4", }, { name: "Ponderosa Pine", parent: "Pine", value: 50, }, { name: "Scots Pine", parent: "Pine", value: 150, }, { name: "White Pine", parent: "Pine", value: 100, }, { name: "Douglas Fir", parent: "Evergreen", value: 150, }, { name: "Juniper", parent: "Evergreen", value: 80, }, { name: "Hemlock", parent: "Evergreen", value: 30, }, { name: "Deciduous", id: "Deciduous", color: "#F9BB00", }, { name: "Oak", parent: "Deciduous", value: 80, }, { name: "Maple", id: "Maple", parent: "Deciduous", value: 180, color: "#F7CE52", }, { name: "Red Maple", parent: "Maple", value: 80, }, { name: "Sugar Maple", parent: "Maple", value: 100, }, { name: "Beech", parent: "Deciduous", value: 50, }, { name: "Willow", parent: "Deciduous", value: 100, }, { name: "Juniper", parent: "Deciduous", value: 90, }, ] %> <%= pb_rails("treemap_chart", props: { chart_data: data, drillable: true, grouped: true, id: "treemap-drillable", title: "Drillable Grouped Tree Species", }) %>
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: "Pepperoni", parent: "Toppings", value: 600, }, { name: "Cheese", parent: "Toppings", value: 510, }, { name: "Mushroom", parent: "Toppings", value: 330, },{ name: "Onions", parent: "Toppings", value: 250, }, { name: "Olives", parent: "Toppings", value: 204, }, { name: "Pineapple", parent: "Toppings", value: 90, }, { name: "Pizza Toppings", id: "Toppings", }, ] %> <%= pb_rails("treemap_chart", props: { chart_data: data, colors: ["data-4", "data-7", "#8E6E53", "#124732"], id: "treemap-colors", title: "Favored Pizza Toppings", }) %>
A custom tooltip format can be specified. The desired format can be passed as a string
of custom HTML to the tooltipHtml
prop.
{point.name}
and {point.value}
are useful values that can be referenced for each point in the graph.
<% data = [ { name: "Pepperoni", parent: "Toppings", value: 600, }, { name: "Cheese", parent: "Toppings", value: 510, }, { name: "Mushroom", parent: "Toppings", value: 330, },{ name: "Onions", parent: "Toppings", value: 250, }, { name: "Olives", parent: "Toppings", value: 204, }, { name: "Pineapple", parent: "Toppings", value: 90, }, { name: "Pizza Toppings", id: "Toppings", }, ] %> <%= pb_rails("treemap_chart", props: { chart_data: data, id: "treemap-tooltip", title: "Favored Pizza Toppings", tooltip_html: "<p>Custom tooltip for {point.name} <br/>with value: {point.value}</p>", }) %>
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
|
vertical_align |
array
|
baseline
super
top
middle
bottom
sub
text-top
text-bottom
|
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 |
---|---|---|---|
height |
string
|
||
chart_data |
array
|
||
colors |
array
|
||
custom_options |
string
|
||
drillable |
boolean
|
false
|
|
grouped |
boolean
|
false
|
|
title |
string
|
||
tooltip_html |
string
|
<span style="font-weight: bold; color:{point.color};">● </span>
{point.name}: <b>{point.value}
</b>
|