1.可以循环展示tooltip的方法
说明:dispatchAction
方法用于触发 ECharts 图表的行为,例如模拟用户的交互行为。在你的代码中,你使用 dispatchAction
方法来模拟鼠标悬停在图表的第一个数据点上。
setAction () {
var app = {
currentIndex: -1,
};
this.timer = setInterval(() => {
var dataLen = this.options.series[0].data.length;
// 取消之前高亮的图形
this.echart.dispatchAction({
type: "downplay",
seriesIndex: 0,
dataIndex: app.currentIndex,
});
app.currentIndex = (app.currentIndex + 1) % dataLen;
// 高亮当前图形
this.echart.dispatchAction({
type: "highlight",
seriesIndex: 0,
dataIndex: app.currentIndex,
});
// 显示 tooltip
this.echart.dispatchAction({
type: "showTip",
seriesIndex: 0,
dataIndex: app.currentIndex,
});
}, 1000);
},
2.饼状图 饼图悬浮 错位
注:series中加 selectedMode: true,selectedOffset: 3,属性
setAction () {
this.echart.on('mouseover', (event) => {
this.echart.dispatchAction({
type: 'select',
seriesIndex: 0,
dataIndex: event.dataIndex
});
})
}