Stacked area
author(s): Torstein Hønsi
by jpeter06
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="parent">
<div id="boton" onclick="showHide()"></div>
<div id="container"> </div>
</div>
<p class="highcharts-description">
Añadimos boton (div id="boton" para mostrar y ocultar linea).
</p>
</figure>
CSS
#container {
height: 400px;
}
#boton{
position:absolute;
color:red;
top:60px;
right:10px;
z-index:10;
width:10px;
height:10px;
border-radius:10px;
box-shadow: 1px 1px 5px black;
cursor:pointer;
border:6px solid white;
background:red;
}
.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 #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
var chart = Highcharts.chart('container', {
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: {
useHTML: true,
text: 'Million tonnes CO<sub>2</sub>-equivalents'
}
},
tooltip: {
shared: true,
headerFormat: '<span style="font-size:12px"><b>{point.key}</b></span><br>'
},
plotOptions: {
series: {
pointStart: 2012
},
area: {
stacking: 'normal',
lineColor: '#666666',
lineWidth: 1,
marker: {
lineWidth: 1,
lineColor: '#666666'
}
}
},
yAxis: {
min: -3000,
max: 27000,
startOnTick: false,
endOnTick: false
},
series: [ {
name: 'Households',
data: [6685, 6535, 6389, 6384, 6251, 5725, 5631, 5047, 5039]
}, {
name: 'Agriculture and hunting',
data: [4752, 4820, 4877, 4925, 15006, 4976, 4946, 4911, 4913]
}, {
name: 'NUCLEAR',
data: [3000, 3000, 3000, 3000, 3000, 3000, 3000, 3000, 3000]
}, {
color:'transparent',
name: 'COMPENSADOR',
showInLegend:false,
data: [2000, 2000, 0, 0, 2175, 2257, 0, 0, 0]
}, {
color:'red',
name: 'Construction1',
data: [-2000, -2000, 3000, 3000, -2175, -2257, 2344, 2176, 2186]
},{
type: 'spline', // LA
color:'red',
name: 'Ocean transport',
data: [0, 12729, 26533, 17798, 10398, 12811, 15483, 16196, 16214]
}]
});
function showHide() {
var s = chart.series[5];
s.update({
visible: !s.visible
});
}