需求:需要将饼图进行自动高亮轮播,实现动态效果
代码:
var app = {
currentIndex: -1
}
var _this = this // 防止需要显示的id获取不到
if (!this.timelet) {
this.timelet = setInterval(function() {
var dataLen = option.series[0].data.length
// 取消之前高亮的图形
_this.myChart.dispatchAction({
type: 'downplay',
seriesIndex: 0,
dataIndex: app.currentIndex
})
app.currentIndex = (app.currentIndex + 1) % dataLen
// 高亮当前图形
_this.myChart.dispatchAction({
type: 'highlight',
seriesIndex: 0,
dataIndex: app.currentIndex
})
// 显示 tooltip
_this.myChart.dispatchAction({
type: 'showTip',
seriesIndex: 0,
dataIndex: app.currentIndex
})
}, 3000)
}
效果: