国产成人精品亚洲777人妖,欧美日韩精品一区视频,最新亚洲国产,国产乱码精品一区二区亚洲

您的位置:首頁技術(shù)文章
文章詳情頁

javascript - 百度echarts series數(shù)據(jù)更新問題

瀏覽:251日期:2022-06-24 16:49:38

問題描述

我直接上個演示地址吧,方便查看問題所在,代碼也是寫在頁面中的默認(rèn)先請求一次,然后定時器,每隔一段時間去請求數(shù)據(jù),更新圖表,但是發(fā)現(xiàn)我請求成功后,想重新 Tcharts.setOption(option)的時候,還是存在著上一次的數(shù)據(jù),比如我第一次請求是2條數(shù)據(jù),然后渲染沒有問題,第二次請求返回1條數(shù)據(jù)的時候,渲染有問題,圖表還存在著上一次的數(shù)據(jù)

我截了下ajax請求的圖片javascript - 百度echarts series數(shù)據(jù)更新問題javascript - 百度echarts series數(shù)據(jù)更新問題

var maxpage = 1; var dataPage = 1; var option = {}; var dataArray ,xAxisArray,legendArray; var Tcharts = echarts.init(document.getElementById(’Tcharts’)); Tcharts.setOption({title: { //是否顯示標(biāo)題組件 show : false},tooltip: { trigger: ’axis’},legend: { data:[], left : ’auto’, right : ’0’, top : ’0’, bottom : ’auto’, padding : 5, itemWidth : 10, itemGap : 20},grid: { show : true, left: ’0’, right: ’3%’, bottom: ’0’, top: ’15%’, containLabel: true, borderColor : ’#ffffff’},toolbox: { show : false, feature: {saveAsImage: {} }},xAxis: { show : true, type: ’category’, data: [], nameGap : 10, boundaryGap : false, nameTextStyle : {color : ’#f2f2f2’ }, axisLabel : { }, axisLine : {show : false,onZero : true,lineStyle : { color : ’#999999’, fontWeight : ’bold’} }, splitLine : {show : false }, axisTick : {lineStyle : { color : ’#ff5a2a’, width : 1},show : false //是否顯示坐標(biāo)軸刻度 }},yAxis: { type: ’value’, axisLine : {show : true,onZero : true,lineStyle : { color : ’#999999’, fontWeight : ’bold’} }, axisLabel : { }, axisTick : {show : false //是否顯示坐標(biāo)軸刻度 }},series: [],textStyle : { fontFamily : ’Helvetica Neue,Helvetica,PingFang SC,Hiragino Sans GB,Microsoft YaHei,Arial,sans-serif’},color : [’#ff5a2a’,’#a981f3’,’#1496ec’,’#55ea84’] //線條顏色列表 }); Tcharts.showLoading({text: '圖表數(shù)據(jù)正在努力加載...' }); //withDate function withDate(data){dataArray = [];xAxisArray = [];legendArray = [];var goods = data.goods,months = data.months;if (data.msg === 1) { for (var g = 0;g < goods.length;g++) {dataArray.push(goods[g]);legendArray.push({icon : ’circle’,name : goods[g].name}); } for (var m = 0;m < months.length;m++) {xAxisArray.push(months[m]); } option = {legend: { data : legendArray},xAxis : { data : xAxisArray},series : dataArray } //console.log(dataArray +':' + xAxisArray + ':' + legendArray); Tcharts.setOption(option);}else {} } //ajax function getDate(){$.ajax({ type: 'post', url: 'http://wy.woawin.com/verify/pricemovements', data : {dataPage : dataPage}, dataType : 'json', async : true, success : function(data){Tcharts.hideLoading();withDate(data);dataPage ++;maxpage = data.maxpage; }}); } getDate(); window.setInterval(function(){if( maxpage >= dataPage){ getDate();}else{ dataPage = 1; getDate();} },10000);

在線演示地下 演示效果

問題解答

回答1:

echarts的setOption說了如果新數(shù)據(jù)沒有覆蓋掉原來的數(shù)據(jù),那么原來數(shù)據(jù)會繼續(xù)重用。

你的series.data之前是一個[{},{}]這樣的形式,重新setOption的時候應(yīng)該是這樣的[{}],另外一個對象就繼續(xù)重用了。

題主可以試試每次都傳兩個進(jìn)去,如果沒有數(shù)據(jù)就傳一個空對象。

個人推測,有什么不對還望指正

let dataArr = [];promise.then(result) { dataArr.fill({}); result.data.forEach((item, index) => dataArr[index] = item); // 使用dataArr 進(jìn)行渲染}

標(biāo)簽: 百度
相關(guān)文章:
主站蜘蛛池模板: 嘉义县| 通河县| 长治县| 祥云县| 兴山县| 和田市| 张家港市| 濮阳县| 政和县| 江门市| 吉林市| 亳州市| 宜城市| 泽州县| 林西县| 界首市| 泰安市| 邢台市| 高要市| 曲水县| 万山特区| 铜梁县| 曲沃县| 潜山县| 涿鹿县| 和平县| 济南市| 诸城市| 财经| 万州区| 永吉县| 富阳市| 河间市| 灯塔市| 云浮市| 丹江口市| 苍梧县| 龙川县| 浦县| 泰来县| 安图县|