方法调用
参数:
mychart echart实例
num: 数据长度
time:轮播一次时间间隔
autoPlay(myChart, option.series[0].data.length, 3000);
// 内容可以不需要修改<br>/**<br>* maChart是echarts初始化的实例对象<br>* num 是series 里面的data长度,传入值可为option.series[0].data.length<br>* time 是时间间隔<br><br>*/<em>export function autoPlay(myChart, num, time) {
const defaultData = { // 设置默认值
time: 3000,
num: 100
};
if (!time) {
time = defaultData.time
}
if (!num) {
num = defaultData.num
}
let count = 0
let timeTicket = null
timeTicket && clearInterval(timeTicket)
timeTicket = setInterval(() => {
myChart.dispatchAction({
type: 'downplay',
seriesIndex: 0 // serieIndex的索引值 可以触发多个
})
myChart.dispatchAction({
type: 'highlight',
seriesIndex: 0,
dataIndex: count
})
myChart.dispatchAction({
type: 'showTip',
seriesIndex: 0,
dataIndex: count
})
count++
if (count >= num) {
count = 0
}
}, time)
myChart.on('mouseover', (params) => {
clearInterval(timeTicket)
myChart.dispatchAction({
type: 'downplay',
seriesIndex: 0
})
myChart.dispatchAction({
type: 'highlight',
seriesIndex: 0,
dataIndex: params.dataIndex
})
myChart.dispatchAction({
type: 'showTip',
seriesIndex: 0,
dataIndex: params.dataIndex
})
})
myChart.on('mouseout', () => {
timeTicket && clearInterval(timeTicket)
timeTicket = setInterval(() => {
myChart.dispatchAction({
type: 'downplay',
seriesIndex: 0 // serieIndex的索引值 可以触发多个
})
myChart.dispatchAction({
type: 'highlight',
seriesIndex: 0,
dataIndex: count
})
myChart.dispatchAction({
type: 'showTip',
seriesIndex: 0,
dataIndex: count
})
count++;
if (count >= num) {
count = 0
}
}, time)
})