echarts 饼图或环形图默认选中高亮

在这里插入图片描述

  // 使用刚指定的配置项和数据显示图表。
        this.myChart.setOption(option);
        let index=0;
        let myChart =this.myChart;//解决echarts中this指向问题
        myChart.dispatchAction({
          type: 'highlight',
          seriesIndex: 0,
          dataIndex: 0
        });
        myChart.on("mouseover", function(e) {
          if (e.dataIndex != index) {
            myChart.dispatchAction({
              type: "downplay",
              seriesIndex: 0,
              dataIndex: index
            });
          }
        });
        myChart.on("mouseout", function(e) {
          index = e.dataIndex;
          myChart.dispatchAction({
            type: "highlight",
            seriesIndex: 0,
            dataIndex: e.dataIndex
          });
        });

上面的代码写在this.myChart.setOption(option)的后面即可在vue中写用的echarts,不能写成this.myChart.dispatchAction({})因为echart会导致this指向问题,这样饼图就不能默认显示。所以将this.myChart赋给变量myChart就可以解决这个问题。下面是实现的效果图,默认显示也可以动态切换显示
在这里插入图片描述
如果想默认显示的是黄色部分的就给dataIndex赋值为0,如果想默认显示红色部分就将dataIndex改为1,如果想默认显示紫色就将dataIndex改为2,以此类推,可以改变默认显示的位置

  • 4
    点赞
  • 9
    收藏
    觉得还不错? 一键收藏
  • 6
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 6
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值