admin管理员组

文章数量:1296858

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...

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...

Share Improve this question edited Aug 16, 2013 at 1:23 SheetJS 22.9k12 gold badges67 silver badges76 bronze badges asked Jun 19, 2012 at 21:44 PoruPoru 8,37022 gold badges67 silver badges90 bronze badges
Add a ment  | 

5 Answers 5

Reset to default 4

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 )

I guess, you want something like this,

chart.series[0].data = [];
chart.redraw();

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 */);
}

Just a guess, but try changing to chart.series = {};?

You can also use setData([])

http://api.highcharts./highcharts#Series.setData()

本文标签: javascriptHighchartsRedraw empty chartStack Overflow