echarts 图例至少保留一个选中

this.echart.on('legendselectchanged', function (params) {
const option = this.getOption()
const selectedLegends = params.selected
const keys = Object.keys(selectedLegends)
const currentLegend = params.name
if (!keys.filter(key => selectedLegends[key]).length) {
option.legend[0].selected[currentLegend] = true
}
option.legend[0].data.forEach((item)=>{
if(item.name == params.name &&selectedLegends[params.name] == true){
option.graphic[0].elements[0].style.text +=item.value
} else if(item.name == params.name &&selectedLegends[params.name] == false){
if (!keys.filter(key => selectedLegends[key]).length) {
option.graphic[0].elements[0].style.text =item.value
} else {
option.graphic[0].elements[0].style.text -=item.value
}
}
})
this.setOption(option, true);
})

你可能感兴趣的:(echarts 图例至少保留一个选中)