echarts 设置全选、反选

2022-07-22  本文已影响0人  9c31078a8e66
            let selectName = ""
            chart.on('legendselectchanged', function(obj) {
                const {selected, name} = obj;
                let status = selected[name]
                let otherStatus = status
                for(let key in selected) {
                    if(key != name) {
                        otherStatus = selected[key]
                        break
                    }
                }
                if (selectName != name) {
                    otherStatus = true
                }
                // 设置状态
                for(let key in selected) {
                    if(key === name) {
                        selected[key] = true
                    } else {
                        selected[key] = !otherStatus
                    }
                }
                option.legend.selected = selected;
                chart.setOption(option);
                selectName = name
            });
上一篇 下一篇

猜你喜欢

热点阅读