先看看效果图
![在这里插入图片描述](https://img-blog.csdnimg.cn/20210610094032506.gif#pic_center)
封装的方法echartsLoop(echartsName,time)
// echarts 自动轮播
global.echartsLoop = function (echartsName,time) {
var currentIndex = -1;
setInterval(function () {
var dataLen = echartsName._model.option.series[0].data.length;
// 取消之前高亮的图形
echartsName.dispatchAction({
type: "downplay",
seriesIndex: 0, //表示series中的第几个data数据循环展示
dataIndex: currentIndex,
});
currentIndex = (currentIndex + 1) % dataLen; //+1表示每次跳转一个
// 高亮当前图形
echartsName.dispatchAction({
type: "highlight",
seriesIndex: 0,
dataIndex: currentIndex,
});
// 显示 tooltip
echartsName.dispatchAction({
type: "showTip",
seriesIndex: 0,
dataIndex: currentIndex,
});
}, time);
}
调用方法
this.global.echartsLoop(r3,1000)