Add HC series dynamically
by dhchow
HTML
<script src="http://highcharts.com/js/testing.js"></script>
<div id="container" style="height: 400px"></div>
<button id="button">Add series</button>
<button id="redraw">Redraw</button>
<button id="recreate">Recreate</button>
JavaScript
var config = {
chart: {
renderTo: 'container'
},
xAxis: {
categories: ['Jan', 'Feb', 'Mar', 'Apr', 'May', 'Jun', 'Jul', 'Aug', 'Sep', 'Oct', 'Nov', 'Dec']
},
series: [{
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]
}]
};
var chart = new Highcharts.Chart(config);
// the button handler
$('#button').click(function() {
if (chart.series.length == 1) {
chart.addSeries({
data: [194.1, 95.6, 54.4, 29.9, 71.5, 106.4, 129.2, 144.0, 176.0, 135.6, 148.5, 216.4]
});
}
});
$('#redraw').click(function(){
chart.redraw();
});
$('#recreate').click(function(){
if (chart) chart.destroy();
chart = new Highcharts.Chart(config);
});