Reputation: 8360
I have a rendered Highcharts chart on a website and I need to empty it after a certain time. Now I tried that with such code but the chart doesn't empty itself/nothing changes...
var chart = new Highcharts.Chart({
// Chart settings
});
// Some other JS
function emptyChart(chart) {
chart.series = [];
chart.redraw();
}
// Some code and a function executes this function after some time
emptyChart(chart);
I also don't get any error in the Firebug console or somewhere else, just nothing happens...
Upvotes: 1
Views: 4904
Reputation: 37578
You can also use setData([])
http://api.highcharts.com/highcharts#Series.setData()
Upvotes: 1
Reputation: 992
A clean way to do this :
function emptyChart(chart) {
while(chart.series.length !=0) {
chart.series[0].hide();
chart.series[0].remove();
}
}
If you want your axis to disappear as well, use the "showEmpty: false" option (check xAxis.showEmpty )
Upvotes: 4
Reputation: 8360
I had this problem already a second time and now I finally found a simple but currently only-working solution: Just create a new, empty Highchart:
function emptyChart(chart) {
chart = new Highcharts.Chart(/* chartOptions */);
}
Upvotes: 2
Reputation: 28995
I guess, you want something like this,
chart.series[0].data = [];
chart.redraw();
Upvotes: 2