// 寫一個函數,參數爲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的自動播放
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.