vue3 echarts 仪表盘,完整代码

在这里插入图片描述

<template>
  <div>
    <div id="chartId" class="chartRef" style="width: 600px; height: 400px;"></div>
  </div>
</template>
<script setup lang="ts">
import * as echarts from "echarts";
import { onMounted } from 'vue';
const colorStyle = [[1,new echarts.graphic.LinearGradient(
                  0, 0, 1, 0, [
                  {
                     offset: 0,
                     color: 'rgba(22, 148, 255, 0.1)',
                  },
                  {
                     offset: 1,
                     color:'rgba(63, 250, 250, 0.9)',
                  }
                  ]
            )]]
const option = {
   backgroundColor: "#0b3c66",
   series: [
      //最外的圆圈(外层刻度)
      {
         type: 'gauge',
         center: [
         '50%',
         '55%'
         ],
         radius: '90%',
         startAngle: 220,
         endAngle: -40,
         min: 0,
         max: 100,
         axisLine: {
            show: true,
            lineStyle: {
               width: 3,
               color:colorStyle
            }
         },
         axisLabel: {
         show: 0
         },
         axisTick: {
            lineStyle: {
               color:'rgba(63,250,250,0.7)',
               width: 1
            },
            length: 5
         },
         splitLine: {
            length: 8,
            lineStyle: {
               color:'rgba(63,250,250,0.8)',
               width: 3
            }
         },
      },
      // 外围刻度(第二层)
      {
         type: 'gauge',
         center: [
         '50%',
         '55%'
         ],
         radius: '80%', // 1行3个
         min: 0,
         max: 100,
         startAngle: 220,
         endAngle: -40,
         axisLine: { // 坐标轴线
            lineStyle: { // 属性lineStyle控制线条样式
               color: colorStyle,
               fontSize: 20,
               width: 2,
               opacity: 1, //刻度背景宽度
            }
         },
         splitLine: {
            show: false
         },
         axisLabel: {
            show: false
         },
         axisTick: {
            show: false
         },
      },
      // 外围刻度(中间有背景颜色那块,包括里面的刻度)
      {
         type: 'gauge',
         center: [
         '50%',
         '55%'
         ],
         radius: '85%', // 1行3个
         splitNumber: 10,
         min: 0,
         max: 100,
         startAngle: 220,
         endAngle: -40,
         //分隔线样式
         axisTick: {
            lineStyle: {
               color:'rgba(63,250,250,0.8)',
               width: 1
            },
            length: 5
         },
         //刻度样式
         axisLine: {
            show: true,
            lineStyle: {
               width: 95,
               color: colorStyle
            }
         },
         //整数分隔线
         splitLine: {
            show: true,
            length: 7,
            lineStyle: {
               color:'rgba(63, 250, 250, 0.8)',
               width: 2
            }
         },
         //刻度数字
         axisLabel: {
            show: true,
            distance: 1,
            textStyle: {
               color:'rgba(63, 250, 250, 0.8)',
               fontSize: '18',
               fontWeight: 'bold'
            }
         },
      },
         //从外数第三条线
      {
         type: 'gauge',
         center: [
         '50%',
         '55%'
         ],
         radius: '60%', // 1行3个
         splitNumber: 10,
         min: 0,
         max: 100,
         startAngle: 220,
         endAngle: -40,
         axisLine: { // 坐标轴线
            lineStyle: { // 属性lineStyle控制线条样式
               color: colorStyle,
               fontSize: 20,
               width: 2,
               opacity: 1, //刻度背景宽度
            }
         },
         splitLine: {
            show: false
         },
         axisLabel: {
            show: false
         },
         pointer: {
            show: false
         },
         axisTick: {
            show: false
         },
         detail: {
            show: 0
         }
      },
      // 内侧指针、数值显示
      {
         name: '',
         center: [
         '50%',
         '50%'
         ],
         type: 'gauge',
         radius: '80%', // 1行3个
         splitNumber: 10,
         min: 0,
         max: 100,
         startAngle: 220,
         endAngle: -40,
         axisLine: {
         show: true,
         lineStyle: {
            width: 50,
            color: [
               [
               1,
               new echarts.graphic.LinearGradient(
                     0, 0, 1, 0, [
                     {
                        offset: 0,
                        color: 'rgba(0, 199, 187, 0)',
                     },
                     {
                        offset: 1,
                        color: 'rgba(0, 199, 187, 0)',
                     }
                     ]
               )
               ],
            ]
         }
         },
         axisTick: {
          show: 0,
         },
         splitLine: {
          show: 0,
         },
         axisLabel: {
          show: 0
         },
         pointer: {
            show: true,
            length: '102%',
            width: 8,
            itemStyle: {
               color:colorStyle
            }
         },
         data: [
         {
            value: 22.8,
            name: '消耗电能\nKWh',
            title: {
               offsetCenter: ['0%', '50%'],
               fontSize: 18,
               color:'#4fe8d6'
            },
            detail: {
               offsetCenter: ['0%', '20%'],
               valueAnimation: true,
               fontSize: 40,
               color:'#4fe8d6'
            }
         }
         ]
      }
   ]
};
onMounted(() => {
  let myChart = echarts.init(document.getElementById("chartId"));
  myChart.setOption(option)
  window.addEventListener('resize', function () {
      myChart.resize()
  })
})
</script>

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

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值