雷达图legend初始化默认选中全部data
但是在我的项目中data有时繁多,不宜全部选中
实例:
async initexampleChart() {
var chart = echarts.init(document.getElementById('example_analysis'), null);
//后端获取一些数据赋值
//const exampleAnalysis = (await this.getexampleAnalysis(...)).data.data;
this.data = [];
this.selected = {};
for(var i = 0; i< exampleAnalysis[1].length; i++) {
this.data.push(exampleAnalysis[1][i].name);
//根据index设置想要默认选中的data,我这里是想默认只显示第一个
if(i === 0) {
this.selected[exampleAnalysis[1][i].name] = true
}else{
this.selected[exampleAnalysis[1][i].name] = false
}
};
//this.indicator = []; //可以动态设置雷达图的几个角角
//for(var i = 0; i < exampleAnalysis[0].length; i++) {
// this.indicator.push({name: exampleAnalysis[0][i], max: 1})
//};
let option = {
legend: {
data: this.data,
selected: this.selected
},
radar: {
indicator: this.indicator
},
series: [
{
name: '',
type: 'radar',
data: exampleAnalysis[1]
}
]
};
chart.setOption(option, true);
},
ps:
indicator 英 [ˈɪndɪkeɪtə( r )] 美 [ˈɪndɪkeɪtər]
n.标志,迹象;方向灯,转向指示灯;指示器,显示器;指示剂;指示(物)种 [ 复数 indicators ]