Streamgraph
author(s): Torstein Hønsi
by Ali Khaled
HTML
<script src="https://code.highcharts.com/highcharts.js"></script>
<script src="https://code.highcharts.com/modules/streamgraph.js"></script>
<script src="https://code.highcharts.com/modules/series-label.js"></script>
<script src="https://code.highcharts.com/modules/annotations.js"></script>
<script src="https://code.highcharts.com/modules/exporting.js"></script>
<script src="https://code.highcharts.com/modules/export-data.js"></script>
<figure class="highcharts-figure">
<div id="container"></div>
<p class="highcharts-description">
Streamgraphs are a type of stacked area charts where the
areas are displaced around a central axis. It is often
used for displaying compound volume across different
categories or over time. This demo visualizes the number of
medals earned in the Winter Olympic Games for each
participating country since 1924, using a relative scale.
</p>
</figure>
CSS
#container {
height: 600px;
}
.highcharts-figure,
.highcharts-data-table table {
min-width: 310px;
max-width: 800px;
overflow: auto;
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
const colors = Highcharts.getOptions().colors;
Highcharts.chart('container', {
chart: {
type: 'streamgraph',
marginBottom: 30,
zoomType: 'x'
},
// Make sure connected countries have similar colors
colors: [
colors[0],
colors[1],
colors[2],
colors[3],
colors[4],
// East Germany, West Germany and Germany
Highcharts.color(colors[5]).brighten(0.2).get(),
Highcharts.color(colors[5]).brighten(0.1).get(),
colors[5],
colors[6],
colors[7],
colors[8],
colors[9],
colors[0],
colors[1],
colors[3],
// Soviet Union, Russia
Highcharts.color(colors[2]).brighten(-0.1).get(),
Highcharts.color(colors[2]).brighten(-0.2).get(),
Highcharts.color(colors[2]).brighten(-0.3).get()
],
title: {
floating: true,
align: 'left',
text: 'Graphics Visual Test'
},
subtitle: {
floating: true,
align: 'left',
y: 30,
text: 'In Progress'
},
xAxis: {
maxPadding: 0,
type: 'category',
crosshair: true,
categories: [
'',
'1924 Chamonix',
'1928 St. Moritz',
'1932 Lake Placid',
'1936 Garmisch-Partenkirchen',
'1940 <i>Cancelled (Sapporo)</i>',
'1944 <i>Cancelled (Cortina d\'Ampezzo)</i>',
'1948 St. Moritz',
'1952 Oslo',
'1956 Cortina d\'Ampezzo',
'1960 Squaw Valley',
'1964 Innsbruck',
'1968 Grenoble',
'1972 Sapporo',
'1976 Innsbruck',
'1980 Lake Placid',
'1984 Sarajevo',
'1988 Calgary',
'1992 Albertville',
'1994 Lillehammer',
'1998 Nagano',
'2002 Salt Lake City',
'2006 Turin',
'2010 Vancouver',
'2014...