Highcharts example
Adding new series data to chart
by grant
HTML
<script src="http://code.highcharts.com/highcharts.js"></script>
<script src="http://code.highcharts.com/modules/exporting.js"></script>
<div id="container1" style="min-width: 400px; height: 400px; margin: 0 auto"></div>
JavaScript
var options1 = {
chart: {
renderTo: 'container1'
},
tooltip: {
formatter: function() {
return 'Extra data: <b>' + this.point.bird + '</b>';
}
},
series: []
};
var drawChart = function (data, name, bird) {
// 'series' is an array of objects with keys: 'name' (string) and 'data' (array)
var newSeriesData = {
name: name,
data: data,
bird: bird
};
// Add the new data to the series array
options1.series.push(newSeriesData);
// If you want to remove old series data, you can do that here too
// Render the chart
var chart = new Highcharts.Chart(options1);
};
var data = [];
var bird =[];
// we get new data
data = [1, 2, 3, 4, 5];
drawChart(data, 'Tokyo', 'coors');
// again
data = [3, 2, 1, 4, 4];
drawChart(data, 'grant', 'coors');
// we get new data
data = [10, 11, 12, 13, 14];
drawChart(data, 'Sydney', 'coors');