echats legend 单选模式轮播实现

  1. 设置legend属性:selectedModel: 'single'

  2. 使用myCharts.dispatchAction 来设置legend的聚焦

broadcast (v) {
          // 如果是false,则消灭轮播
            if (v === false) return clearInterval(this.timer) 
            // 获取legend的data
            const data = this.myChart.getOption().legend[0].data
            // 首次总是从0开始的
            let i = 0
            // 开始轮播
            this.timer = setInterval(() => {
                // 激活
                this.myChart.dispatchAction({ type: 'legendToggleSelect', name: data[ ++i % data.length ] })
            }, 3500)
}

你可能感兴趣的:(echats legend 单选模式轮播实现)