Echartsjs 柱形图加折线图 启用datazoom,滑动图标之后更新数据,不能覆盖原数据的问题。旧的折线会出现在图表上,目前解决办法:1、setOption之前调用 .clear(),2、给 series data 空数组,然后setOption,再给data新数组,再次setOption
配置项如下
option = {
dataZoom: {
type: 'slider',
show: true,
xAxisIndex: [0],
start: 1,
end: 35
},
xAxis: [{
type: 'category',
boundaryGap: true,
data: [1, 2, 3, 4, 5, 6, 7, 8]
},
{
type: 'category',
boundaryGap: true,
data: (function() {
var res = [];
var len = 10;
while (len--) {
res.push(10 - len - 1);
}
return res;
})()
}
],
yAxis: [{
type: 'value',
scale: true,
name: '价格',
max: 30,
min: 0,
boundaryGap: [0.2, 0.2]
},
{
type: 'value',
scale: true,
name: '预购量',
max: 50,
min: 0,
boundaryGap: [0.2, 0.2]
}
],
series: [{
name: '预购队列',
type: 'bar',
xAxisIndex: 1,
yAxisIndex: 1,
data: [1, 2, 3, 4, 5, 6, 7, 8, 1, 2, 3, 4, 5, 6, 7, 8, 1, 2, 3, 4, 5, 6, 7, 81, 2, 3, 4, 5, 6, 7, 8]
},
{
name: '最新成交价',
type: 'line',
data: [1, 2, 3, 4, 5, 6, 7, 8, 1, 2, 3, 4, 5, 6, 7, 8, 1, 2, 3, 4, 5, 6, 7, 81, 2, 3, 4, 5, 6, 7, 81, 2, 3, 4, 5, 6, 7, 8]
}
]
};
setInterval(function() {
var abc = [];
var bcd = [];
option.series[0].data = abc,
option.series[1].data = bcd,
abc.push(10);
bcd.push(3);
myChart.clear();
myChart.setOption(option, true);
}, 5000);