饼图设置最大值默认选中

饼图设置最大值默认选中

//上面跟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
        });
      });
©著作权归作者所有,转载或内容合作请联系作者
【社区内容提示】社区部分内容疑似由AI辅助生成,浏览时请结合常识与多方信息审慎甄别。
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。

友情链接更多精彩内容