I created a chart using highcharts and I am looking to update it, but I am struggling with this particular line of code that is adding random data instead of the data I want to use from JavaScript.
// Add the new series.
chart.addSeries({ data: Highcharts.map(Array(12), Math.random) }, false);
Additional code:
$(".test").change(function() {
var value = this.getAttribute("value");
while (chart.series.length > 0) {
chart.series[0].remove(true);
}
if (value == 'a') {
loadA(chart);
} else if (value == 'b') {
chart.xAxis[0].update({categories: ['Sun', 'Mon', 'Tue']});
chart.addSeries({
name: 'Rainfall4',
type: 'column',
color: '#FF00FF',
data:[100, 280, 300, 490, 670, 900]
});
chart.yAxis[0].setTitle({ text: "Raw" });
} else if (value == 'c') {
chart.xAxis[0].update({categories: ['Oranges', 'Pears', 'Pinneaples', 'other']});
Check out the Jsfiddle link below:
For a similar effect, you can use:
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] );
});