Echarts仪表盘实现平均值和实时值-定制版

背景:想在仪表盘上看到指标对应的平均值,在仪表盘下方显示指标的实时值

最终效果图如下:
在这里插入图片描述
代码实现:

let centerArr = ['50%', '78%']
option = {
    grid: {
      right: '0%',
      top: '0%',
      left: '0%',
      bottom: '0%',
      containLabel: true
    },
    series: [
      {
        name: '圆点刻度',
        type: 'gauge',
        radius: '135%',
        center: centerArr,
        z: 3,
        splitNumber: 100,
        startAngle: 180,
        endAngle: -0,
        min: 0,
        max: 100,
        axisLine: {
          show: false
        },
        splitLine: {
          show: false
        },
        axisLabel: {
          show: true,
          distance: -23,
          formatter: function (val) {
            if (val == 85) { // 假如平均值是85,则给小球设置样式
              return '{primary|}'
            }
            return ''
          },
          rich: { // 使用rich语法设置均值小球的样式
            primary: {
              width: 8,
              height: 8,
              borderRadius: 20,
              borderWidth: '1px',
              borderColor: '#FF4B4B',
              backgroundColor: '#FFFFFF'
            }
          }
        },
        axisTick: {
          show: false
        },
        detail: {
          show: false
        }
      },
      {
        name: '线条外圈', // 刻度背景
        type: 'gauge',
        z: 2,
        radius: '135%',
        // splitNumber: 10,
        startAngle: 180,
        endAngle: -0,
        min: 0,
        max: 100,
        center: centerArr, // 整体的位置设置
        axisLabel: {
          show: false
        },
        // 仪表盘轴线相关配置
        axisLine: {
          lineStyle: {
            width: 2,
            color: [
              [0.25, '#FF4B4B'],
              [0.5, '#FF9E57'],
              [0.75, '#1F8FE6'],
              [1, '#64CDBB']
            ]
          }
        },
        axisTick: {
          length: 6,
          distance: 2,
          lineStyle: {
            color: 'auto',
            width: 2
          }
        },
        // 分隔线样式
        splitLine: {
          length: 10,
          distance: 2,
          lineStyle: {
            color: 'auto',
            width: 3
          }
        },
        pointer: {
          show: false
        },
        detail: {
          show: 0
        }
      },
      {
        name: '刻度尺', // 刻度背景
        type: 'gauge',
        z: 1,
        radius: '135%',
        splitNumber: 0,
        startAngle: 180,
        endAngle: -0,
        center: centerArr, // 整体的位置设置
        axisLine: {
          lineStyle: {
            width: 2,
            color: [
              [0.25, '#FF4B4B'],
              [0.5, '#FF9E57'],
              [0.75, '#1F8FE6'],
              [1, '#64CDBB']
            ]
          }
        },
        splitLine: {
          show: false
        },
        data: [
          {
            value: 74.97 // 指标的实时值,假如值为74.97
          }
        ],
        axisLabel: {
          show: false
        },
        pointer: {
          icon: 'path://M12.8,0.7l12,40.1H0.7L12.8,0.7z',
          length: '12%',
          width: 10,
          offsetCenter: [0, '-65%'],
          itemStyle: {
            color: 'auto'
          }
        },
        axisTick: {
          show: false
        },
        detail: {
          formatter: function (val) {
            // 图表中间文字数据展示
            return '{bold|' + val + '%' + '\n}{gray|' + props.rateName + '}' //props.rateName指的是指标的名称,类似图中的实时指标
          },
          rich: {
            gray: {
              fontSize: 16,
              fontWeight: 400,
              color: '#F8FDFF'
            },
            bold: {
              fontSize: 32,
              // lineHeight: 135,
              fontWeight: 700,
              color: '#F8FDFF'
            }
          },
          offsetCenter: ['0', '10%']
        }
      }
    ]
  }```

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

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值