Tree map with levels
author(s):
Jon Arild Nygård
by Vitaliy Kretsul
September 07, 2022
HTML
<script src="https://code.highcharts.com/stock/highstock.src.js"></script>
<script src="https://code.highcharts.com/modules/treemap.js"></script>
<script src="https://code.highcharts.com/modules/accessibility.js"></script>
<figure class="highcharts-figure">
<div id="container"></div>
<p class="highcharts-description">
This chart shows a tree map with a hierarchy, where the
groups are labelled with a different text style from the
child nodes, and the nodes are grouped together by color.
</p>
</figure>
CSS
.highcharts-figure,
.highcharts-data-table table {
min-width: 320px;
max-width: 600px;
margin: 1em auto;
}
.highcharts-data-table table {
font-family: Verdana, sans-serif;
border-collapse: collapse;
border: 1px solid #ebebeb;
margin: 10px auto;
text-align: center;
width: 100%;
max-width: 500px;
}
.highcharts-data-table caption {
padding: 1em 0;
font-size: 1.2em;
color: #555;
}
.highcharts-data-table th {
font-weight: 600;
padding: 0.5em;
}
.highcharts-data-table td,
.highcharts-data-table th,
.highcharts-data-table caption {
padding: 0.5em;
}
.highcharts-data-table thead tr,
.highcharts-data-table tr:nth-child(even) {
background: #f8f8f8;
}
.highcharts-data-table tr:hover {
background: #f1f7ff;
}
JavaScript
Highcharts.StockChart('container', {
series: [{
type: "treemap",
layoutAlgorithm: 'stripes',
alternateStartingDirection: true,
levels: [{
level: 1,
layoutAlgorithm: 'sliceAndDice',
dataLabels: {
enabled: true,
align: 'left',
verticalAlign: 'top',
style: {
fontSize: '15px',
fontWeight: 'bold'
}
}
}],
data: [{
id: 'A',
name: 'Nord-Norge',
color: "#50FFB1"
}, {
id: 'B',
name: 'Trøndelag',
color: '#F5FBEF'
}, {
id: 'C',
name: 'Vestlandet',
color: "#A09FA8"
}, {
id: 'D',
name: 'Østlandet',
color: '#E7ECEF'
}, {
id: 'E',
name: 'Sørlandet',
color: '#A9B4C2'
}, {
name: 'Troms og Finnmark',
parent: 'A',
value: 70923
}, {
name: 'Nordland',
parent: 'A',
value: 35759
}, {
name: 'Trøndelag',
parent: 'B',
value: 39494
}, {
name: 'Møre og Romsdal',
parent: 'C',
value: 13840
}, {
name: 'Vestland',
parent: 'C',
value: 31969
}, {
name: 'Rogaland',
parent: 'C',
value: 8576
}, {
name: 'Viken',
parent: 'D',
value: 22768
}, {
name: 'Innlandet',
parent: 'D',
value: 49391
},
{
name: 'Oslo',
parent: 'D',
value: 454
},
{
name: 'Vestfold og Telemark',
parent: 'D',
value: 15925
},
{
name:...