Highcharts Demo
author(s): Torstein Hønsi
by sperske
HTML
<script src="https://code.highcharts.com/highcharts.js"></script>
<div id="container"></div>
CSS
#container {
min-width: 300px;
max-width: 800px;
margin: 0 auto;
}
JavaScript
Highcharts.chart('container', {
title: {
text: 'Highcharts with a shared tooltip formatter'
},
xAxis: {
categories: [
'Jan', 'Feb', 'Mar', 'Apr', 'May', 'Jun',
'Jul', 'Aug', 'Sep', 'Oct', 'Nov', 'Dec'
],
crosshair: true
},
tooltip: {
formatter: function () {
let {points, x} = this;
points = points.slice(1);
const total = points.reduce((total, point) => total + point.y, 0);
return `${x}<br/><strong>Total ${total}</strong>` + points.reduce((out, point) => `${out}<br/><strong>${point.series.name}</strong>:${point.y}`, '');
/*
return this.points.reduce(function (s, point) {
return s + '<br/>' + point.series.name + ': ' +
point.y + 'm';
}, '<b>' + this.x + '</b>');*/
},
shared: true
},
series: [{
data: [1216.4, 1194.1, 195.6, 154.4, 129.9, 171.5, 1106.4, 1129.2, 1144.0, 1176.0, 1135.6, 1148.5]
},{
data: [29.9, 71.5, 106.4, 129.2, 144.0, 176.0, 135.6, 148.5, 216.4, 194.1, 95.6, 54.4]
}, {
data: [216.4, 194.1, 95.6, 54.4, 29.9, 71.5, 106.4, 129.2, 144.0, 176.0, 135.6, 148.5]
}]
});