简体   繁体   English

高图-重绘空白图表

[英]Highcharts - Redraw empty chart

I have a rendered Highcharts chart on a website and I need to empty it after a certain time. 我在网站上有一个渲染的Highcharts图表,我需要在一段时间后将其清空。 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... 我在Firebug控制台或其他地方也没有任何错误,什么也没发生...

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 ) 如果您还希望轴消失,请使用“ showEmpty:false”选项(检查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: 我已经第二次遇到了这个问题,现在我终于找到了一个简单但目前只能使用的解决方案:只需创建一个新的空Highchart:

function emptyChart(chart) {
    chart = new Highcharts.Chart(/* chartOptions */);
}

Just a guess, but try changing to chart.series = {}; 只是一个猜测,但是尝试更改为chart.series = {}; ?

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM