当前位置: 首页 > article >正文

vue3之echarts仪表盘

vue3之echarts仪表盘

效果如下:
在这里插入图片描述
版本
"echarts": "^5.5.1"

核心代码:

<template>
  <div ref="chartRef" class="circle"></div>
</template>
<script lang="ts" setup>
import { ref, onMounted, onBeforeMount } from 'vue';
import * as echarts from 'echarts';

const chartRef = ref(null);
const percent = ref(23);
let chart: any = null;

const topChartOptions = (value: number) => {
  return {
    series: [
      {
        name: 'S',
        z: 3,
        type: 'gauge', // 仪表盘
        center: ['50%', '82%'],
        radius: '135%',
        detail: {
          show: false,
        },
        title: {
          show: false,
        },
        data: [
          {
            value,
            name: 'Percent',
          },
        ],
        startAngle: '178', // 仪表盘起始角度
        endAngle: '2', // 仪表盘结束角度
        min: 0,
        max: 100,
        axisLine: {
          show: true,
          lineStyle: {
            roundCap: true,
            width: 8,
            color: [
              [
                value / 100,
                new echarts.graphic.LinearGradient(0, 0, 1, 0, [
                  {
                    offset: 0,
                    color: 'rgba(11, 163, 250, 1)',
                  },
                  {
                    offset: 1,
                    color: 'rgba(227, 250, 255, 1)', // 100% 处的颜色
                  },
                ]),
              ],
              [1, 'rgba(4, 211, 251, 0)'],
            ],
          },
        },
        axisTick: {
          show: false,
        },
        axisLabel: {
          show: false,
        },
        splitLine: {
          show: false,
        },
        pointer: {
          length: '22%',
          width: 4,
          icon: 'rect',
          offsetCenter: [0, '-87%'],
          itemStyle: {
            color: 'RGBA(191, 255, 238, 1)',
          },
        },
      },
      {
        name: 'T',
        z: 2,
        type: 'gauge', // 仪表盘
        center: ['50%', '82%'],
        radius: '135%',
        detail: {
          show: false,
        },
        title: {
          show: false,
        },
        data: [
          {
            value: 100,
            name: 'Percent',
          },
        ],
        startAngle: '178', // 仪表盘起始角度
        endAngle: '2', // 仪表盘结束角度
        min: 0,
        max: 100,
        axisLine: {
          show: true,
          lineStyle: {
            roundCap: true,
            width: 10,
            color: [
              [
                1,
                new echarts.graphic.LinearGradient(0, 0, 1, 0, [
                  {
                    offset: 0,
                    color: 'transparent',
                  },
                  {
                    offset: value / 100,
                    color: 'rgba(255, 192, 1, 1)',
                  },
                  {
                    offset: 1,
                    color: 'rgba(255, 242, 204, 1)', // 100% 处的颜色
                  },
                ]),
              ],
              [1, 'rgba(255, 192, 1, 0)'],
            ],
          },
        },
        axisTick: {
          show: false,
        },
        axisLabel: {
          show: false,
        },
        splitLine: {
          show: false,
        },
        pointer: {
          show: false,
        },
      },
    ],
  };
};

const initChart = () => {
  if (!chart) chart = echarts.init(chartRef.value);
  chart.setOption(topChartOptions(percent.value));
};

onMounted(() => {
  initChart();
});

const destroyChart = () => {
  if (!chart) {
    return;
  }
  chart.dispose();
  chart = null;
};

onBeforeMount(() => {
  destroyChart();
});
</script>
<style lang="scss" scoped>
.circle {
  width: 314px;
  height: 191px;
}
</style>


http://www.kler.cn/a/570823.html

相关文章:

  • leetcode_字典树 140. 单词拆分 II
  • Leetcode 206 -反转链表
  • iOS实现一个强大的本地状态记录容器
  • 爬虫系列之【数据解析之bs4】《四》
  • 决策树(Decision Tree):机器学习中的经典算法
  • 多用户MIMO预编码技术的对比
  • 基于RK3588的重症监护信息系统应用解决方案
  • 动漫短剧小程序源码|动漫短剧app搭建
  • NL2SQL-基于Dify+阿里通义千问大模型,实现自然语音自动生产SQL语句
  • 【愚公系列】《Python网络爬虫从入门到精通》040-Matplotlib 概述
  • VS2022远程调试Ubuntu中的C++程序
  • C#使用技巧
  • 使用python运行网格世界环境下 TD算法
  • QML、Qt Quick /Qt中绘制圆形
  • mysql xa 事务理解
  • 【电路笔记】-MOD计数器
  • 大数据“调味“ ,智慧“添香“,看永洪科技助力绝味食品数字化新征程
  • -bash: lsof: command not found
  • FastAdmin 的响应式设计如何提升用户体验
  • 【工具推荐】在线提取PDF、文档、图片、论文中的公式