【无标题】环改变选中

该文章描述了一个Vue子组件与父组件交互的过程,用于控制ECharts图表的高亮选择。父组件调用`getDefaultSelected`方法,子组件内部通过`dispatchAction`处理高亮和淡化效果。当鼠标悬停在图表上时,会动态改变数据项的选中状态。
摘要由CSDN通过智能技术生成
父:; 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,
        });
      });
    },

点击右侧按钮左侧环形图高亮选择随之改变 

 

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值