// 写一个函数,参数为chart图表的ref参数, 自动播放的间隔时间time
// 注意chart的option配置项series 要写成数据的形式,如果为对象 修改函数里面series的判断
autoPlayToopTip (chartRef, time = 1500) {
let dataIndex = -1
let dataLen = 0
if (typeof chartRef !== 'undefined' && typeof chartRef.options.series !== 'undefined') {
if (chartRef.options.series.length > 0 && typeof chartRef.options.series[0].data !== 'undefined') {
dataLen = chartRef.options.series[0].data.length
}
setInterval(() => {
chartRef.dispatchAction({
type: 'downplay',
playState: true,
seriesIndex: 0,
dataIndex
})
dataIndex = (dataIndex + 1) % dataLen
chartRef.dispatchAction({
type: 'highlight',
playState: true,
seriesIndex: 0,
dataIndex
})
// 显示 tooltip
chartRef.dispatchAction({
type: 'showTip',
seriesIndex: 0,
playState: true,
dataIndex
})
}, time)
}
},
Echarts 图表tooltip的自动播放
最新推荐文章于 2025-03-18 10:12:34 发布