Echarts 图表tooltip的自动播放

  • Echarts 图表tooltip的自动播放
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
// 写一个函数,参数为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)
}
},

Comentarios

Your browser is out-of-date!

Update your browser to view this website correctly. Update my browser now

×