Stacked area
author(s):
Torstein Hønsi
HTML
<script src="https://code.highcharts.com/highcharts.js"></script>
<script src="https://code.highcharts.com/modules/exporting.js"></script>
<script src="https://code.highcharts.com/modules/export-data.js"></script>
<script src="https://code.highcharts.com/modules/accessibility.js"></script>
<figure class="highcharts-figure">
<div id="container"></div>
<p class="highcharts-description">
A demo showing a stacked area chart, also sometimes referred to as a
mountain chart. In a stacked chart, the data series values are added
together to make up a total.
</p>
</figure>
CSS
body {
font-family:
-apple-system,
BlinkMacSystemFont,
"Segoe UI",
Roboto,
Helvetica,
Arial,
"Apple Color Emoji",
"Segoe UI Emoji",
"Segoe UI Symbol",
sans-serif;
background: var(--highcharts-background-color);
color: var(--highcharts-neutral-color-100);
}
#container {
height: 400px;
}
.highcharts-figure,
.highcharts-data-table table {
min-width: 310px;
max-width: 800px;
margin: 1em auto;
}
.highcharts-data-table table {
font-family: Verdana, sans-serif;
border-collapse: collapse;
border: 1px solid var(--highcharts-neutral-color-10, #e6e6e6);
margin: 10px auto;
text-align: center;
width: 100%;
max-width: 500px;
}
.highcharts-data-table caption {
padding: 1em 0;
font-size: 1.2em;
color: var(--highcharts-neutral-color-60, #666);
}
.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 tbody tr:nth-child(even) {
background: var(--highcharts-neutral-color-3, #f7f7f7);
}
.highcharts-description {
background: light-dark(#f2f6f2, #323232);
border-radius: 0 4px 4px 0;
border-left: 2px solid light-dark(#1d6aff, #fff);
font-size: 0.8rem;
font-style: italic;
padding: 8px 16px;
margin: 2em 10px 1em;
}
JavaScript
Highcharts.chart('container', {
dataTable: {
columns: {
Year: [
2012, 2013, 2014, 2015, 2016, 2017, 2018,
2019, 2020, 2021, 2022
],
'Ocean transport': [
13234, 12729, 11533, 17798, 10398, 12811,
15483, 16196, 15060, 13365, 13301
],
Households: [
6686, 6536, 6389, 6384, 6251, 5719,
5611, 5040, 5079, 5088, 4988
],
'Agriculture and hunting': [
4812, 4872, 4961, 5001, 5070, 5035,
5045, 5004, 5015, 5076, 4935
],
'Air transport': [
3502, 3844, 4139, 4351, 3802, 4020,
4461, 5074, 1558, 1247, 2694
],
Construction: [
2019, 2189, 2150, 2217, 2179, 2258,
2348, 2196, 2018, 2180, 2127
]
}
},
chart: {
type: 'area'
},
title: {
text: 'Greenhouse gases from Norwegian economic activity'
},
subtitle: {
text: 'Source: ' +
'<a href="https://www.ssb.no/en/statbank/table/09288/"' +
'target="_blank">SSB</a>'
},
yAxis: {
title: {
text: 'Million tonnes CO₂-equivalents'
}
},
tooltip: {
shared: true,
headerFormat: '<span style="font-size:12px"><b>{point.key}</b></span>' +
'<br>'
},
plotOptions: {
series: {
dataMapping: {
x: 'Year'
}
},
area: {
stacking: 'normal',
lineColor: '#666666',
lineWidth: 1,
marker: {
lineWidth: 1,
lineColor: '#666666'
}
}
},
series: [{
dataMapping: {
y: 'Ocean transport'
}
}, {
dataMapping: {
y: 'Households'
}
}, {
dataMapping:...