父:; this.$refs.chart.getDefaultSelected(item, index);
子:getDefaultSelected(params, index = 0) {
this.chart.dispatchAction({
type: "highlight",
seriesIndex: 0,
dataIndex: 0,
});
for (var i = 0; i < this.data.length; i++) {
this.data[i].selected = false;
this.chart.dispatchAction({
type: "downplay",
seriesIndex: 0,
dataIndex: i,
});
}
const idx = this.data.findIndex((el) => el.name == params.name);
if (idx !== -1) {
this.data[idx].selected = true;
}
this.chart.setOption({
legend: { selected: { [params.name]: true } },
});
this.chart.dispatchAction({
type: "highlight",
seriesIndex: 0,
dataIndex: idx,
});
this.chart.on("mouseover", (e) => {
if (e.dataIndex != index) {
this.chart.dispatchAction({
type: "downplay",
seriesIndex: 0,
dataIndex: index,
});
}
});
this.chart.on("mouseout", (e) => {
index = e.dataIndex;
this.chart.dispatchAction({
type: "highlight",
seriesIndex: 0,
dataIndex: e.dataIndex,
});
});
},
点击右侧按钮左侧环形图高亮选择随之改变