vue3之仪表盘

vue3之仪表盘

效果:

在这里插入图片描述

版本
“echarts”: “^5.5.1”

核心代码:

<!--
 * @Description: 圆环组件封装
 * @Version: 1.0
 * @Autor: qh
-->

<template>
  <div ref="chartRef" class="circle"></div>
</template>

<script lang="ts" setup>
import { ref, onMounted } from 'vue';
import * as echarts from 'echarts';

const props = defineProps({
  percent: {
    type: Number,
    default: 0,
  },
});

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

const rich = {
  bule: {
    fontSize: 22,
    fontFamily: 'DINPro',
    color: '#fff',
    padding: [6, 0, 0, 0],
  },
  white: {
    fontSize: 12,
    color: '#fff',
    padding: [10, 0, 0, 0],
  },
};

const topChartOptions = (value: number) => {
  return {
    tooltip: {
      show: false,
      formatter: '{a} <br/>{b} : {c} ({d}%)',
    },
    series: [
      {
        name: 'S',
        z: 3,
        type: 'gauge', // 仪表盘
        center: ['49.5%', '58%'],
        radius: '95%',
        detail: {
          formatter: (value: any) => {
            return '{bule|' + value + '}{white|%}';
          },
          rich,
          offsetCenter: ['0%', '0%'],
        },
        title: {
          show: false,
        },
        data: [
          {
            value,
            name: 'Percent',
          },
        ],
        axisLine: {
          show: true,
          lineStyle: {
            roundCap: true,
            width: 7,
            color: [
              [
                value / 100,
                new echarts.graphic.LinearGradient(0, 0, 1, 0, [
                  {
                    offset: 0,
                    color: 'rgba(0, 255, 231, 0.5)',
                  },
                  {
                    offset: 0.5,
                    color: 'rgba(0, 255, 231, 0.8)', // 100% 处的颜色
                  },
                  {
                    offset: 1,
                    color: 'rgba(0, 255, 231, 0.5)', // 100% 处的颜色
                  },
                ]),
              ],
              [1, 'rgba(4, 211, 251, 0)'],
            ],
          },
        },
        axisTick: {
          show: false,
        },
        axisLabel: {
          show: false,
        },
        splitLine: {
          show: false,
        },
        pointer: {
          length: '14%',
          width: 2,
          icon: 'rect',
          offsetCenter: [0, '-87%'],
          itemStyle: {
            color: 'rgba(0, 255, 231, 1)',
          },
        },
      },
      {
        name: 'T',
        z: 2,
        type: 'gauge', // 仪表盘
        center: ['49.5%', '58%'],
        radius: '96%',
        detail: {
          show: false,
        },
        title: {
          show: false,
        },
        data: [
          {
            value: 100,
            name: 'Percent',
          },
        ],
        axisLine: {
          show: true,
          lineStyle: {
            roundCap: true,
            width: 8,
            color: [
              [
                1,
                new echarts.graphic.LinearGradient(0, 0, 1, 0, [
                  {
                    offset: 0,
                    color: 'rgba(150, 179, 180, 1)',
                  },
                  {
                    offset: value / 100,
                    color: 'rgba(150, 179, 180, 0.5)',
                  },
                  {
                    offset: 1,
                    color: 'rgba(150, 179, 180, 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(props.percent));
};

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

onBeforeUnmount(() => {
  if (chart) {
    chart.clear();
    chart.dispose();
    chart = null;
  }
});
</script>

<style scoped lang="scss">
.circle {
  width: 132px;
  height: 113px;
  // 根据实际情况加背景图
  background: url('@/assets/img/inspection/overview-bg.png') no-repeat;
}
</style>

  • 1
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
vue子组件仪表盘有多个选择,其中两个常用的是vue-speedometer和简易的风速仪表盘显示小组件。vue-speedometer是一个Vue组件库,用于显示速度表,可以使用d3的仪表来实现。你可以使用yarn或者npm安装该组件库,然后通过import引入VueSpeedometer组件来使用。另外,简易的风速仪表盘显示小组件也是一个使用vue开发的封装好的组件,可以实时显示风速,适用于大数据界面、仪表盘显示界面等等。希望这些信息能对你有所帮助。<span class="em">1</span><span class="em">2</span><span class="em">3</span> #### 引用[.reference_title] - *1* [vue-speedometer:Vue组件库,用于显示使用D3的类似仪表的车速表](https://download.csdn.net/download/weixin_42134554/18323964)[target="_blank" data-report-click={"spm":"1018.2226.3001.9630","extra":{"utm_source":"vip_chatgpt_common_search_pc_result","utm_medium":"distribute.pc_search_result.none-task-cask-2~all~insert_cask~default-1-null.142^v93^chatsearchT3_1"}}] [.reference_item style="max-width: 33.333333333333336%"] - *2* [vue实现简易风速仪表显示小组件](https://download.csdn.net/download/qq_43053266/12917392)[target="_blank" data-report-click={"spm":"1018.2226.3001.9630","extra":{"utm_source":"vip_chatgpt_common_search_pc_result","utm_medium":"distribute.pc_search_result.none-task-cask-2~all~insert_cask~default-1-null.142^v93^chatsearchT3_1"}}] [.reference_item style="max-width: 33.333333333333336%"] - *3* [ruoyi-vue-pro yudao 项目报表设计器 积木报表模块启用及相关SQL脚本](https://download.csdn.net/download/zengwenbo225566/88234865)[target="_blank" data-report-click={"spm":"1018.2226.3001.9630","extra":{"utm_source":"vip_chatgpt_common_search_pc_result","utm_medium":"distribute.pc_search_result.none-task-cask-2~all~insert_cask~default-1-null.142^v93^chatsearchT3_1"}}] [.reference_item style="max-width: 33.333333333333336%"] [ .reference_list ]
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值