echarts饼图,默认选择,自动选中,dispatchAction

echarts饼图,默认选择,自动选中,dispatchAction

效果图

在这里插入图片描述

初始化

var myChart = this.$echarts.init(document.getElementById('pie'));

option

{
  color: ['#F33B3F', '#FF850A', '#F8C649', '#00CFFF'],
  tooltip: {
    show: false,
    trigger: 'item',
  },
  legend: {
    selectedMode: false,
    right: 10,
    top: '15%',
    bottom: 20,
    itemHeight: 10,
    itemWidth: 10,
    orient: 'vertical',
    align: 'auto',
    itemGap: 10,
    textStyle: {
      color: '#FFFFFF',
      fontSize: 12 + 'px',
      padding: 5,
    },
    icon: 'circle',
    itemStyle: {
      borderWidth: 0,
    },
  },
  series: [
    {
      name: '异常',
      type: 'pie',
      radius: ['55%', '80%'],
      center: ['35%', '50%'],
      selectedMode: 'single',
      selectedOffset: 10,
      legendHoverLink: false,
      itemStyle: {
        borderColor: 'none',
      },
      emphasis: {
        label: {
          show: true,
          fontSize: '40',
          fontWeight: 'bold'
        }
      },
      label: {
        show: false,
        position: 'center',
        formatter: '{bt|{b}}\n{dt|{d}%}',
        rich: {
          bt: {
            fontSize: 14 + 'px',
            fontFamily: 'PingFangSC-Regular, PingFang SC',
            fontWeight: 400,
            color: '#EEEEEE',
            height: 36,
          },
          dt: {
            fontSize: 20 + 'px',
            fontFamily: 'HelveticaNeue-Bold, HelveticaNeue',
            fontWeight: 'bold',
            color: '#FFFFFF',
          },
        },
      },
      data: [
        { value: 10, name: '红色告警' },
        { value: 20, name: '橙色告警' },
        { value: 30, name: '黄色告警' },
        { value: 40, name: '蓝色告警' },
      ],
      tooltip: {
        borderColor: '#f00',
      },
    },
  ],
}

选中模块

myChart.dispatchAction({
  type: 'highlight',
  seriesIndex: 0,
  dataIndex: 1,
});

取消选中模块

代码如下(示例):

myChart.dispatchAction({
  type: 'downplay',
  seriesIndex: 0,
  dataIndex: 1,
});
  • 1
    点赞
  • 7
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值