饼图设置最大值默认选中

饼图设置最大值默认选中

//上面跟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
        });
      });

© 版权声明
THE END
如果内容对您有所帮助,就支持一下吧!
点赞0 分享
道枝振作的头像 - 宋马
评论 抢沙发

请登录后发表评论

    暂无评论内容