echarts环形图数量最大的数据默认高亮显示

var chartDom = document.getElementById('main');
var myChart = echarts.init(chartDom);
var option = {
    tooltip: this.tooltip,
    legend: this.legend,
    series: this.series,
};
option.series[0].data = this.data;
myChart.setOption(option);
window.addEventListener('resize', () => {
    myChart.resize();
});
// 默认高亮展示数量最大的数据
myChart.dispatchAction({
  type: 'highlight',
  seriesIndex: 0,
  dataIndex: this.total,
});
myChart.on('mouseover', (v) => {
  if (v.dataIndex != this.total) {
    // 高亮显示悬停的那块
    myChart.dispatchAction({
      type: 'hideTip',
      seriesIndex: 0,
      dataIndex: this.total,
    });
    // 当检测到鼠标悬停事件,取消所有选中高亮
    myChart.dispatchAction({
      type: 'downplay',
      seriesIndex: 0,
      dataIndex: this.total,
    });
  }
});

// 检测鼠标移出后显示之前默认高亮的那块
myChart.on('mouseout', (v) => {
  myChart.dispatchAction({
    type: 'showTip',
    seriesIndex: 0,
    dataIndex: this.total,
  });
  myChart.dispatchAction({
    type: 'highlight',
    seriesIndex: 0,
    dataIndex: this.total,
  });
});
series: [
  {
    type: 'pie',
    top: '15%',
    radius: ['40%', '80%'],
    avoidLabelOverlap: false,
    // label: {
    //   show: false,
    //   position: 'center',
    // },
    label: {
      fontSize: 15,
      lineHeight: 20,
      position: 'center',
      formatter: (params) => {
        return '';
      },
      emphasis: {
        formatter: (params) => {
          this.total = params.dataIndex;
          //切换非默认选项配置数据展示
          return (
            '{Proportiondefault|' +
            params.percent.toFixed(2) +
            '%}' +
            '\n{name|' +
            params.name +
            '}'
          );
        },
      },
      rich: {
        Proportion: {
          //切换的数字参数配置
          fontSize: 40, //显示样式大小
          backgroundColor: 'white', //覆盖数据的背景
        },
        name: {
          //切换的,name名字配置
          color: '#333',
          fontSize: 16,
          backgroundColor: 'white',
        },
        Proportiondefault: {
          fontSize: 22,
          backgroundColor: 'white',
        },
      },
    },

    emphasis: {
      label: {
        show: true,
        fontSize: 20,
        fontWeight: 'bold',
      },
    },
    labelLine: {
      show: false,
    },
    data: [],
  },
],

  • 11
    点赞
  • 11
    收藏
    觉得还不错? 一键收藏
  • 1
    评论
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值