Echarts 仪表盘

本文详细展示了如何使用ECharts库在网页上创建一个包含多个动态元素的仪表盘图表,包括外部间隔条形、动态线条和内部数据展示。代码实例包括图形初始化、数据绑定和响应式调整。

1、效果图

2、代码

createTenantChartOne(){
  var myChart1 = this.$echarts.init(document.getElementById('tenant-chart-1'));
  var dataArr = 82;
  var title = '仪表盘';
  let option = {
    graphic: {
      type: 'text',
      left: 'center',
      top: '85%',
      style: {
        text: title,
        textAlign: 'center',//居中对齐
        fill: '#999',//填充色
        fontSize: 14,
        fontWeight: 400,
        fontFamily: "Source Han Sans CN",
      },
    },
    series: [
      {
        name: "外部间隔条形",
        type: "gauge",
        radius: '113%',
        z: 5,
        splitNumber: 20,
        startAngle: 225,
        endAngle: -45,
        axisLine: {
          lineStyle: {
            opacity: 0
          }
        },
        axisLabel: {
          show: false,
        },
        axisTick: {
          show: true,
          length: 4,
          splitNumber: 1,
          lineStyle: {
            color: '#F1F1F1',
            width: 1
          }
        },
        splitLine: {
          show: false
        },
        detail: {
          show: false
        },
        title: {
          show: false,
        }
      },
      {
        name: "外部线",
        type: "gauge",
        radius: '85%', // 动态
        startAngle: 225,
        endAngle: -45,
        axisLine: {
          lineStyle: {
            color: [
              [1, '#F1F1F1'] // 动态
            ],
            width: 1
          }
        },
        axisLabel: {
          show: false,
        },
        axisTick: {
          show: false,
        },
        splitLine: {
          show: false,
        },
        detail: {
          show: false
        },
        title: { //标题
          show: false,
        }
      },
      {
        name: "间隔条形",
        type: "gauge",
        radius: '104%',
        z: 4,
        splitNumber: 20,
        startAngle: 225,
        endAngle: -45,
        axisLine: {
          lineStyle: {
            opacity: 0
          }
        },
        axisLabel: {
          show: false,
        },
        axisTick: {
          show: true,
          length: 12,
          splitNumber: 1,
          lineStyle: {
            color: '#fff',
            width: 1
          }
        },
        splitLine: {
          show: false
        },
        detail: {
          show: false
        },
        title: {
          show: false,
        }
      },
      {
        name: "数据",
        type: 'gauge',
        radius: '78%',
        z: 3,
        startAngle: 225,
        endAngle: -45,
        max: 100,
        // 仪表盘的线,颜色值为一个数组
        axisLine: {
          show: true,
          lineStyle: {
            width: 12,
            opacity: 1,
            color: [
              [
                dataArr / 100,
                {
                  x: 0,
                  y: 0,
                  x1: 1,
                  y1: 1,
                  colorStops: [
                    {
                      offset: 0,
                      color: 'rgba(65, 249, 255, 0.5059)',
                    },
                    {
                      offset: 1,
                      color: 'rgba(19, 124, 255, 1)',
                    },
                  ],
                },
              ],
              [1, '#F4F4F4'],
            ],
          },
        },
        tooltip: {
          show: false
        },
        axisLabel: {
          show: false,
        },
        axisTick: {
          show: false,
        },
        splitLine: {
          show: false
        },
        detail: {
          show: true,
          fontWeight: 'bold',
          offsetCenter: [0, 0],//水平、垂直偏移
          formatter: (val) => [`{a|${dataArr}%}`].join(''),
          rich: {
            a: {
              fontSize: 20,
              lineHeight: 38,
              fontFamily: 'Source Han Sans',
              fontWeight: 500,
              color: '#1479EA',
            },
          },
        },
        pointer: {
          show: false,
          width: 3,
        },
        data: [{
          name: '',
          value: dataArr
        }]
      },
      {
        type: 'gauge',
        radius: '62%',
        z: 3,
        startAngle: 225,
        endAngle: -45,
        max: 100,
        axisLine: {
          show: false,
        },
        splitLine: {
          show: false
        },
        axisTick: {
          show: false
        },
        axisLabel: {
          show: false
        },
        splitLabel: {
          show: false
        },
        pointer: {
          icon: 'circle', // 箭头图标
          length: '5%',
          width: 14,
          height: 14,
          offsetCenter: [0, '-88%'], // 箭头位置
          itemStyle: {
            color: [
              [
                dataArr / 100,
                {
                  x: 0,
                  y: 0,
                  x1: 1,
                  y1: 1,
                  colorStops: [
                    {
                      offset: 0,
                      color: 'rgba(65, 249, 255, 0.5059)',
                    },
                    {
                      offset: 1,
                      color: 'rgba(19, 124, 255, 1)',
                    },
                  ],
                },
              ],
              [1, '#F4F4F4'],
            ],
            shadowBlur: 10
          },
        },
        detail: {
          show: false,
        },
        title: {
          show: false
        },
        data: [{
          value: dataArr,
        }]
      },
      {
        name: '内圆环',
        type: 'pie',
        radius: ['51%', '49%'],
        hoverAnimation: false,
        tooltip: {
          show: false
        },
        cursor: "default",
        labelLine: {
          "normal": {
            "show": false
          }
        },
        itemStyle: {
          color: 'rgba(0, 0, 0, 0.01)'
        },
        animation: false,
        data: [1]
      },
    ]
  }
  myChart1.setOption(option);
  setTimeout(function () {
    window.addEventListener("resize",()=>{
      myChart1.resize()
    })
  }, 200)
},

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值