Echarts 计算每份占比(等分)

const doDashboard = (val: any) => {
  if (val >= 0 && val < 75) {
    return val * 30 / 75
  } else if (val >= 75 && val <= 85) {
    return 30 + (val - 75) * 40 / 10
  } else {
    return 70 + (val - 85) * 30 / 15
  }
} 


option = {
    series: [
      {
        type: "gauge",
        startAngle: 190,
        endAngle: -10,
        min: 0,
        max: 100,
        axisLine: {
          lineStyle: {
            width: 15,
            color: [
              [0.3, "#91BB7E"],
              [0.7, "#F7DD6F"],
              [1, "#D66474"]
            ]
          }
        },
        pointer: {
          //指针
          icon: "path://M12.8,0.7l12,40.1H0.7L12.8,0.7z",
          length: "60%", //指针长度
          width: 5,
          offsetCenter: [0, "-60%"],
          itemStyle: {
            color: "auto"
          }
        },
        axisTick: {
          show: false,
          distance: -30,
          length: 8,
          lineStyle: {
            color: "#fff",
            width: 2
          }
        },
        splitLine: {
          show: false,
          distance: -20,
          lineStyle: {
            color: "#fff",
            width: 4
          }
        },
        axisLabel: {
          distance: 30,
          fontSize: 12,
          formatter: function (value: any) {
            if (value === 30) {
              return 75 + "%";
            } else if (value === 70) {
              return 85 + "%";
            } else {
              return "";
            }
          },
        },
        detail: {
          fontSize: 20,
          valueAnimation: true,
          color: "auto",
          show: true,
          offsetCenter: [0, -30],
          formatter: function () {
            return dashboardData.valueNumber + "%";
          }
        },
        data: [
          {
            value: doDashboard(dashboardData.valueNumber),
            name: dashboardData.title,
            title: {
              lineHeight: 20,
              offsetCenter: [0, 0],
              fontSize: 12
            }
          }
        ]
      }
    ]
  };
  var chartDom = document.getElementById('main') as HTMLElement;
  var myChart = echarts.init(chartDom);
  option && myChart.setOption(option);

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值