背景
以下是一段简单的循环定时触发echarts实例toolTip action的简单代码
startToolTipLoop() {
let index = 0;
const nameArr = ['俄罗斯', '蒙古', '哈萨克斯坦', '中国', '美国', '越南'];
if (this.timer) {
clearInterval(this.timer);
this.timer = null;
}
const callback = () => {
this.switchTooltip(this.chart, nameArr[index]);
// 更新索引(使用取模运算实现循环)
index = (index + 1) % nameArr.length;
};
callback(); // 立即执行第一次提示
this.timer = setInterval(callback, 3000);
},
switchTooltip(chart, name) {
console.log('switchTooltip name ', name);
// 显示tooltip
this.chart.dispatchAction({
type: 'showTip',
geoIndex: 0,
// geoId: 'geo1',
name
});
},
预期是在render图表的函数中去调用此方法就可循环触发,但是toolTip并没有出现,将dispatchAction中的type改为highlight却能生效,说明geo和name配置应该没错才对。
解决
修改dispatchAction,改为seriesIndex定位即可
this.chart.dispatchAction({
type: 'showTip',
seriesIndex: 0,
name
});