ElementStacks
HTML
<script src="http://highcharts.com/js/testing.js"></script>
<div id="container" style="height: 400px"></div>
<button id="button">Set new data</button>
JavaScript
var chart = new Highcharts.Chart({
chart: {
renderTo: 'container'
},
xAxis: {
plotBands: [{
color: '#80FF80',
from: 7.5,
to: 4.5}]
},
series: [{
data: []
//data: [29.2, 144.0, 176.0, 135.6, 148.5, 216.4, 194.1, 195.6, 54.4, 29.9, 71.5, 106.4]
//plotBands set up when chart is declared DO NOT work when there's no series data to start
//swap the comments to demonstrate
}]
});
// the button action
$('#button').click(function() {
chart.series[0].setData([129.2, 144.0, 176.0, 135.6, 148.5, 216.4, 194.1, 95.6, 54.4, 29.9, 71.5, 106.4]);
//WORKAROUND
//var i;
//for(i=chart.options.xAxis.plotBands.length-1; i>=0; i--) {
// chart.series[0].xAxis.removePlotBand(chart.options.xAxis.plotBands[i].id);
// chart.series[0].xAxis.addPlotBand(chart.options.xAxis.plotBands[i]);
//}
});