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

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.mrgr.cn/news/92982.html

相关文章:

  • RPA 职业前景:个人职场发展的 “新机遇”
  • 动态SQL
  • 【经验分享】Ubuntu vmware虚拟机存储空间越来越小问题(已解决)
  • Unity 打包后EXE运行出现Field to Load il2cpp的一种情况
  • [KEIL]单片机技巧 01
  • 2025-03-03 学习记录--C/C++-PTA 7-38 数列求和-加强版
  • 【监督学习】支持向量机步骤及matlab实现
  • Excel的行高、列宽单位不统一?还是LaTeX靠谱
  • 从DNS到TCP:DNS解析流程和浏览器输入域名访问流程
  • Vue盲区扫雷
  • 大语言模型学习
  • 【弹性计算】弹性裸金属服务器和神龙虚拟化(一):功能特点
  • 大语言模型学习--LangChain
  • GPIO及其应用
  • 【弹性计算】弹性裸金属服务器和神龙虚拟化(二):适用场景
  • 年后 总结
  • Ubuntu20.04下各类常用软件及库安装汇总(联想Y9000P24款)
  • 【Mac】git使用再学习
  • 《从0到1:用Python在鸿蒙系统开发安防图像分类AI功能》
  • CSS—text文本、font字体、列表list、表格table、表单input、下拉菜单select