echarts图表注册点击事件,要在我们初始化后进行。
以vue项目中echarts为例:
myChart.on("legendselectchanged",(e)=>{ }) 图例的点击事件
this.myChart = this.$e.init(this.$el); // init dom元素
this.myChart.setOption(this.chartOption, true); // 转载配置信息
this.myChart.on("legendselectchanged",(e)=>{ // 给legend注册点击事件
if (e.name =='瞪羚企业') {
console.log('这是瞪羚企业');
let type = this.option._data.initChart.find(item=>{
if (item.text=='瞪羚企业') {
console.log(item,'瞪羚企业');
return item
}
})
console.log(type,'瞪羚企业的type');
this.option.checkedLegend({type:type.type}) // 调用更新环形echarts图标的方法,更改下面小模块的数据
let newType = {
ratio: type.ratio,
text: type.text+'-'+type.value+'家',
type: type.type,
value: type.value
}
this.option.checkedData = newType // 更改大模块的数据
}
this.myChart.setOption(this.chartOption, true); // 再次转载配置信息,因为点击是事件对数据做了一些改动,所以再次加载信息,才会生效。
})