echarts legend 的单选模式以及轮播技巧

1、设置 legend 属性: selectedMode: '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)
}
原文地址:https://www.cnblogs.com/CyLee/p/9967756.html