«

echarts图表自动滚动代码

六思逸 发布于 阅读:2985 JavaScript


        pieActive(myChart, option, data) {
            let index = -1; //高亮所在下标
            let dataLength = "";
            let type = 0;
            if (option.series.length > 1) {
                option.series.forEach((item, index) => {
                    if (item.type == "bar") {
                        dataLength = option.series[index].data.length;
                        type = 1;
                    } else if (item.type == "surface") {
                        dataLength = data.length;
                    }
                });
            } else {
                dataLength = option.series[0].data.length; // 当前饼图有多少个扇形
            }
            // 用定时器控制饼图高亮
            let interval = setInterval(() => {
                // 清除之前的高亮
                myChart.dispatchAction({
                    type: "downplay",
                    seriesIndex: type,
                    dataIndex: index
                });
                index = (index + 1) % dataLength;
                // 当前下标高亮
                myChart.dispatchAction({
                    type: "showTip",
                    seriesIndex: type,
                    dataIndex: index
                });
                myChart.dispatchAction({
                    type: "highlight",
                    seriesIndex: type,
                    dataIndex: index
                });

                if (index > dataLength) {
                    index = 0;
                }
            }, 2000);
            // this.activeInterval.push(interval)
        },

echarts图表自动滚动代码 echarts图表


扫描二维码,在手机上阅读
收到2条评论
avatar
爱你的东子 10 个月前
你是我见过最会插表的程序员
回复
avatar
谢谢 10 个月前
生动形象,太好了,我已经学会了,感谢老师,老师你真好
回复