highcharts:实时刷新highcharts图表,内存不断增加,导致内存溢出。该怎么解决
直接使用例子代码还是修改了代码,如果有修改,请提供修改后的内容?
if (this.highchart == null) {
this.highchart = HighCharts.chart("wave", {
accessibility: {
keyboardNavigation: {
enabled: true,
skipNullPoints: true,
},
},
chart: {
type: "line",
zoomType: "xy",
plotBorderWidth: 3,
plotBorderColor: "#383838", //黑色
},
title: {
margin: 5,
align: "left",
text: "波形图",
style: {
fontWeight: "bold",
fontSize: "12px",
},
},
credits: {
enabled: false,
},
legend: {
enabled: false, //关闭图例
},
xAxis: {
gridLineWidth: 1
},
yAxis: {
gridLineWidth: 1,
title: {
text: null,
},
},
exporting: {
filename: "波形图 " + " 机组:" + _this.$store.getters.g_checkFJ.name + "," + _this.waveTitle, //导出的文件名
},
tooltip: {
enabled: false,
},
series: [
{
name: _this.seriesName,
pointStart: 1,
data: dataWaveArr,
allowPointSelect: true,
lineWidth: 1,
color: "#3535FA", //深蓝
marker: {
states: {
hover: {
fillColor: "white",
lineColor: "green",
lineWidth: 1,
radiusPlus: 1,
lineWidthPlus: 1,
radius: 2,
},
},
},
states: {
hover: {
lineWidthPlus: 0,
},
},
},
],
},
function (chart) {
_this.wavedetailsLabel = chart.renderer.label(
_this.waveTitle,
chart.plotLeft + 40,
chart.plotTop - 25
);
_this.wavedetailsLabel.add();
chart.xAxis[0].setCategories(intTicks);
_this.wavetoolTip = chart.renderer.label(
"",
chart.plotLeft + 60,
chart.plotTop
);
_this.wavetoolTip.add();
}
);
} else {
console.log("波形图在更新");
if (this.wavedetailsLabel != null) {
this.wavedetailsLabel.attr({ text: this.waveTitle });
}
this.highchart.series[0].setData(dataWaveArr);
this.highchart.series[0].name = this.seriesName;
if (this.waveintTicksNewLen != this.waveintTicksOldLen) {
this.waveintTicksOldLen = this.waveintTicksNewLen;
this.highchart.xAxis[0].setCategories(intTicks);
this.highchart.xAxis[0].update({ tickInterval: vtickInterval });
}
}
这是修改的代码,数据是实时更新的。
代码中的问题不大,修改替换下面的代码试试
console.log("波形图在更新");
if (this.wavedetailsLabel != null) {
this.wavedetailsLabel.attr({ text: this.waveTitle });
}
let redraw = this.waveintTicksNewLen != this.waveintTicksOldLen;
this.highchart.series[0].update({name: this.seriesName}, false);
this.highchart.series[0].setData(dataWaveArr, !redraw);
if (redraw) {
this.waveintTicksOldLen = this.waveintTicksNewLen;
this.highchart.xAxis[0].setCategories(intTicks, false);
this.highchart.xAxis[0].update({ tickInterval: vtickInterval });
}
好的,我试了。但是内存还是不断增加。每更新一次数据,内存就往上增加,增加到内存溢出,界面就崩溃了。