饼图设置最大值默认选中
//上面跟let option = { series[{}]};
let index = 0; //默认选中高亮模块索引
if (obj) { //obj是饼图的数据对象
let max = obj.reduce( //计算出最大值以及最大值对应的索引
(a, c, i) => (c.value > a ? ((index = i), c.value) : a),
0
);
}
let myEhart = this.chart;// 防止修改this指向
this.chart.setOption(option);
this.chart.dispatchAction({
type: "highlight",//高亮
seriesIndex: 0,
dataIndex: index
}); //设置默认选中高亮部分
this.chart.on("mouseover", function(e) {
console.log(e);
if (e.dataIndex != index) {
myEhart.dispatchAction({
type: "downplay",//取消高亮
seriesIndex: 0,
dataIndex: index
});
}
});
this.chart.on("mouseout", function(e) {
index = e.dataIndex;
myEhart.dispatchAction({
type: "highlight",//高亮
seriesIndex: 0,
dataIndex: index
});
});