echarts icon indicating copy to clipboard operation
echarts copied to clipboard

求助!echarts加载大量数据,内存不断增加导致浏览器很卡甚至崩溃;

Open zhang122622623 opened this issue 9 years ago • 6 comments

One-line summary [问题简述]

vue构建的单页面网站,echarts绘制了一张包含7条线,每条最多720个点的图表; 页面跳转后发现每次加载该页面内存都会上升50M左右,,用不了多久内存就满了; 在vue钩子函数beforeDestory中已经设置了dispose()方法在组件销毁前清除图形实例,但是并不起作用; 尝试过只绘制一两条线,这种情况下页面加载内存上升在3、4M的样子; 实在搞不清楚为什么图形实例都被销毁了,为何内存还会增加;

Version & Environment [版本及环境]

  • ECharts version [ECharts 版本]:echarts: 3.6.2;
  • Browser version [浏览器类型和版本]:chrome 61
  • OS Version [操作系统类型和版本]:win7;

Expected behaviour [期望结果]

页面跳转,实例销毁,内存能基本保持稳定;

ECharts option [ECharts配置项]

option = {

}

Other comments [其他信息]

zhang122622623 avatar Nov 08 '17 07:11 zhang122622623

做了下调试,在dipose()方法调用前后分别打印出当前的echarts实例: beforeDestroy(){ //this.chart3_1.clear(); console.log(this.chart3_1) this.chart3_1.dispose(); console.log(this.chart3_1,this.chart3_1.isDisposed()) }, echarts实例销毁后,.isDisposed()确实返回true; 但是两次均能返回实例,这是不是有问题, 实例销毁后不应该是返回空值吗?不理解。。

zhang122622623 avatar Nov 08 '17 08:11 zhang122622623

(1)是否能提供 option? (2)this.chart3_1.dispose(); 这句话并不能清空 this.chart3_1。

100pah avatar Nov 08 '17 08:11 100pah

那应该如何清空呢?option比较长: this.chart3_1.setOption({ title: { text: (this.isEn)? this.$t('SG')+' (mg/dL)':this.$t('SG')+' (mmol/L)', textStyle: this.textStyle, padding: this.titlePadding, }, tooltip:{}, xAxis: [{ type: 'time', boundaryGap: false, min:new Date(this.startTime), max:new Date(this.startTime+8.64e7), axisLine: {lineStyle: {color: '#ccc'}}, splitNumber: 24, splieLine:{show:true}, axisLabel:{ margin: 15, textStyle: {color: '#282828', baseline: 'middle'} , formatter:function (value,index) { let H = new Date(value).getHours(); if(index<24){ if(index%3===0){ H = H<10 ? ('0'+H+':00' ): H+':00'; return H; }else{ return ' '; } }else{ return H+24+':00'; } } }, }], yAxis: [{ type: 'value', min:0,max:(this.isEn)? 400:25, axisLabel: this.yAxisLabel, axisLine: {lineStyle: {color: '#ccc'}}, boundaryGap: false, axisTick: {length: 0}, }], grid: this.grid, animation:false, dataZoom:[ { id:'dataZoomX', type:'slider', xAxisIndex:0, filterMode:'filter', realtime:true, start:0, end:100, labelFormatter:function (value) { return ''; } } ], series: [ { type:'scatter', data:this.DataSG[0], markArea: { data: [ [{yAxis: (this.isEn)?this.DataS.target_low18:this.DataS.target_low}, {yAxis:(this.isEn)?this.DataS.target_high18:this.DataS.target_high}]], tooltip:{show:false,}, silent:true, itemStyle: {normal: {color: 'rgba(211,255,213,0.6)',},} }, markLine: { data: [{ yAxis:(this.isEn)?this.DataS.hypo*18:this.DataS.hypo}], symbol:['circle','circle'], silent:true, symbolSize: 1, tooltip:{backgroundColor:'#777',formatter:''+this.DataS.hypo.toFixed(1)+'',textStyle:{color:'#f00'}}, lineStyle: {normal: { color: 'rgba(255,0,0,0.5)', type: 'solid', }}, label:{normal:{show:false}}, }, itemStyle: {normal: {color:'#3ce8dc',}}, tooltip:{backgroundColor:'#777', formatter: function(params){ let date = params.value[0]; let time = auth.formatterDate5(date); if(params.value[1]>0){ return time[0]+':'+time[1]+', '+params.value[1]; }else{ return time[0]+':'+time[1]+', warm up' } }, textStyle:{color:'#3ce8dc'} }, symbolSize:3, }, { type:'scatter', data:this.DataSG[1], itemStyle: {normal: {color:'#2842d2',}}, tooltip:{backgroundColor:'#777', formatter:function(params){ let date = params.value[0]; let time = auth.formatterDate5(date); if(params.value[1]>0){ return time[0]+':'+time[1]+', '+params.value[1]; }else{ return time[0]+':'+time[1]+', warm up' } }, textStyle:{color:'#2842d2'} }, symbolSize:3, }, { type:'scatter', data:this.DataSG[2], itemStyle: {normal: {color:'#79bd39',}}, tooltip:{backgroundColor:'#777', formatter:function(params){ let date = params.value[0]; let time = auth.formatterDate5(date); if(params.value[1]>0){ return time[0]+':'+time[1]+', '+params.value[1]; }else{ return time[0]+':'+time[1]+', warm up' } }, textStyle:{color:'#79bd39'} }, symbolSize:3, }, { type:'scatter', data:this.DataSG[3], itemStyle: {normal: {color:'#dce573',}}, tooltip:{backgroundColor:'#777', formatter:function(params){ let date = params.value[0]; let time = auth.formatterDate5(date); if(params.value[1]>0){ return time[0]+':'+time[1]+', '+params.value[1]; }else{ return time[0]+':'+time[1]+', warm up' } }, textStyle:{color:'#dce573'} }, symbolSize:3, }, { type:'scatter', data:this.DataSG[4], itemStyle: {normal: {color:'#e61795',}}, tooltip:{backgroundColor:'#777', formatter:function(params){ let date = params.value[0]; let time = auth.formatterDate5(date); if(params.value[1]>0){ return time[0]+':'+time[1]+', '+params.value[1]; }else{ return time[0]+':'+time[1]+', warm up' } }, textStyle:{color:'#e61795'} }, symbolSize:3, }, { type:'scatter', data:this.DataSG[5], itemStyle: {normal: {color:'#c9711e',}}, tooltip:{backgroundColor:'#777', formatter:function(params){ let date = params.value[0]; let time = auth.formatterDate5(date); if(params.value[1]>0){ return time[0]+':'+time[1]+', '+params.value[1]; }else{ return time[0]+':'+time[1]+', warm up' } }, textStyle:{color:'#c9711e'} }, symbolSize:3, }, { type:'scatter', data:this.DataSG[6], itemStyle: {normal: {color:'#a922d9',}}, tooltip:{backgroundColor:'#777', formatter:function(params){ let date = params.value[0]; let time = auth.formatterDate5(date); if(params.value[1]>0){ return time[0]+':'+time[1]+', '+params.value[1]; }else{ return time[0]+':'+time[1]+', warm up' } }, textStyle:{color:'#a922d9'} }, symbolSize:3, }, { type: 'scatter', data: this.calib, symbol:'image://static/legend/calib.png', tooltip:{backgroundColor:'#333', formatter:function(params){ let date = params.value[0]; let time = auth.formatterDate5(date); return params.value[2]+' '+time[0]+':'+time[1]+',Calibration '+params.value[1]; }, }, }, { type: 'scatter', data: this.bg, symbol:'image://static/legend/calibrate_1.png', tooltip:{backgroundColor:'#333', formatter:function(params){ let date = params.value[0]; let time = auth.formatterDate5(date); return params.value[2]+' '+time[0]+':'+time[1]+',BG '+params.value[1]; }, }, }, ], },false,true);

zhang122622623 avatar Nov 08 '17 08:11 zhang122622623

echarts.dispose(dom); 然后可以重新渲染

zl19921218 avatar Nov 27 '17 03:11 zl19921218

@zl19921218 上面已经说过,dispose()方法并不能清空对象; 现在采用的方法是手动清空相关对象变量,包括图形实例和相关的数据项,这样处理在一定程度上减少了内存的增加;但由于js中变量清空后内存并不会马上被回收,因此采用了比较笨的方法,在特定的时刻刷新整个页面,这样就基本解决了问题。

zhang122622623 avatar Nov 27 '17 06:11 zhang122622623

@zhang122622623 你是有一个刷新页面的操作吗?但是我看到你的顶部写到是基于 Vue 的单页应用,不冲突吗~

xuchao008 avatar Apr 28 '18 11:04 xuchao008