下载水球图

  1. npm install echarts

  2. npm install echarts-liquidfill

在对应组件中引入也可在main.ts中引入水球图

 import * as echarts from 'echarts'import 'echarts-liquidfill'

使用echarts必须给echarts图表设置宽高

<template><div class="water-wave"><div ref="liquidEchart" style="width: 200px; height: 200px"></div></div></template>

此处绑定ref 是为了给图表数据 宽高是为了显示水球图

效果图

底部发光图是切图定位显示

代码如下

<template><div class="water-wave"><div ref="liquidEchart" style="width: 200px; height: 200px"></div></div></template><script lang="ts">import { defineComponent, onMounted, ref } from 'vue'import * as echarts from 'echarts'import 'echarts-liquidfill'export default defineComponent({name: 'WaterWave',setup() {// 组件逻辑const liquidEchart = ref<HTMLElement>()onMounted(() => {initLiquidEchart()})const initLiquidEchart = () => {let myChart = echarts.init(liquidEchart.value!)let value = 0.6// 把配置和数据放这里myChart.setOption({title: {// 标题text: '',textStyle: {// 标题的样式color: '#888', // 字体颜色fontFamily: 'Microsoft YaHei', // 字体fontSize: 24,fontWeight: '400',align: 'center', // 文字的水平方式baseline: 'middle',position: 'inside',verticalAlign: 'middle', // 文字的垂直方式},left: 'center', // 定位top: '20%',},series: [{type: 'liquidFill',radius: '80%', //水球大小center: ['50%', '50%'],waveAnimation: true,color: [{type: 'linear',x: 0,y: 0,x2: 0,y2: 1,colorStops: [{offset: 0,color: '#138FE2',},{offset: 1,color: '#126ABC',},],globalCoord: false,},],data: [0.3, 0.3], // data个数代表波浪数amplitude: 10, //振幅backgroundStyle: {borderWidth: 2, //边框大小borderColor:'rgba(17, 94, 176, 0.8)',//边框颜色color: 'rgba(17, 94, 176, 0.4)',},label: {normal: {textStyle: {fontSize: 24,fontWeight: 'bold',color: '#fff',},},},outline: {borderDistance: 0,itemStyle: {borderWidth: 4,borderColor: 'transparent',},},}],})}return { liquidEchart }},})</script><style lang="scss" scoped  />

借鉴代码

效果图

<template><div class="water-wave"><div ref="liquidEchart" style="width: 200px; height: 200px"></div></div>
</template><script lang="ts">
import { defineComponent, onMounted, ref } from 'vue'
import * as echarts from 'echarts'
import 'echarts-liquidfill'export default defineComponent({name: 'WaterWave',setup() {// 组件逻辑const liquidEchart = ref<HTMLElement>()onMounted(() => {initLiquidEchart()})const initLiquidEchart = () => {let myChart = echarts.init(liquidEchart.value!)let value = 0.6// 把配置和数据放这里myChart.setOption({title: {// 标题text: '',textStyle: {// 标题的样式color: '#888', // 字体颜色fontFamily: 'Microsoft YaHei', // 字体fontSize: 24,fontWeight: '400',align: 'center', // 文字的水平方式baseline: 'middle',position: 'inside',verticalAlign: 'middle', // 文字的垂直方式},left: 'center', // 定位top: '20%',},series: [{type: 'liquidFill',radius: '78%', // 水球大小waveAnimation: true,center: ['50%', '50%'],color: ['#FFEFD6', '#FEAF2E'],data: [value, value], // data个数代表波浪数amplitude: 10, //振幅// 图形样式itemStyle: {opacity: 1, // 波浪的透明度shadowBlur: 0, // 波浪的阴影范围},backgroundStyle: {borderWidth: 1, // 边框的宽度borderColor: '#FEAF2E', // 边框颜色color: '#fff',},label: {// 数据展示样式show: true,textStyle: {color: '#000',insideColor: '#fff',fontSize: 30,fontWeight: 600,},formatter: (params: any) => {return `${(params.value * 100).toFixed(1)}/200` // 文字显示},},outline: {show: false,},},],})}return { liquidEchart }},
})
</script><style lang="scss" scoped src="./index.scss" />

vue3项目中封装为组件

新建组件liquidFill.vue

<template></template><script lang="ts" setup>
// 1. 引入
import { nextTick, watch } from 'vue';
import echarts from '@/assets/ts/echarts';
import 'echarts-liquidfill';
const props = defineProps({// 父容器IDpid: {type: String,required: true,},title: {type: String,required: true,},value: {type: Number,required: true,},// 水球图背景颜色bgColor: {type: String,default: 'rgba(32, 165, 255, 0.3)',},// 波纹的颜色color: {type: String,default: '#20a5ff',},// 单位unit: {type: String,default: '',},
});nextTick(() => {// 2. 容器const container = document.querySelector('#' + props.pid) as HTMLElement;if (container) initChart(container);
});
// 3. 初始化 echarts 实例, 将配置添加给 echarts 实例
let myChart: echarts.ECharts | null = null;
const initChart = (container?: HTMLElement) => {if (!myChart) myChart = echarts.init(container as HTMLElement);myChart.setOption(option);
};watch(() => props.value,newVal => {option.series[0].data[0] = newVal;initChart();},
);
// 4.配置项
const option = {title: {text: props.title,x: '40%',y: '88%',textStyle: {fontSize: 14,fontWeight: '100',color: '#fff',lineHeight: 16,textAlign: 'center',},},series: [{type: 'liquidFill',radius: '70%',center: ['50%', '40%'],color: [{type: 'linear',x: 0,y: 0,x2: 0,y2: 1,colorStops: [{offset: 0,// color: "#446bf5",color: props.color,},{offset: 1,color: '#2ca3e2',},],globalCoord: false,},],data: [props.value, 0.5], // data个数代表波浪数backgroundStyle: {borderWidth: 1,color: props.bgColor,},label: {// show:false,fontSize: 50,color: '#fff',formatter: '{c}' + props.unit,},outline: {show: false,borderDistance: 0,itemStyle: {borderWidth: 2,borderColor: '#112165',},},},],
};
</script>

使用

  <div id="load-chart" v-if="curSiteInfo.loadPer || curSiteInfo.loadPer === 0"><LiquidFill pid="load-chart" title="负荷率" :value="curSiteInfo.loadPer" unit="%"></LiquidFill></div><div id="power-factor" v-if="curSiteInfo.Pf || curSiteInfo.Pf === 0"><LiquidFill pid="power-factor" title="功率因数" :value="curSiteInfo.Pf" color="rgba(37, 227, 255)"bgColor="rgba(37, 227, 255,0.3)"></LiquidFill></div>
 #load-chart,#power-factor {width: 50%;height: 83%;margin-top: 8%;background: url('@/assets/img/Profile/DomesticService/bottom.png') no-repeat 80% 93%;background-size: 95% 20%;}

vue3+ts项目中使用水球图相关推荐

  1. Vue3+TS项目中element-plus自动导入组件后,找不到文件

    问题 原因 从报错代码来看,这是一个ts错误,而且是找不到名称 是没有将*.d.ts文件加入到tsconfig.json配置文件中,所以Typescript还不认识它们 解决 //找到项目根目录下 t ...

  2. TypeScript及TypeScript在vue3.0项目中的基本使用

    一. TypeScript是什么 TypeScript 是一种由微软开发的自由开源的编程语言,主要提供了类型系统和对 ES6的支持.它是JavaScript的一个超集,扩展了JavaScript的 语 ...

  3. 使用vue-cli创建vue3+ts项目

    使用vue-cli创建vue3+ts项目 提示:该文章为vue3+ts的!该文章是博主看的B站尚硅谷视频课来进行整理的!尚硅谷的课真的很不错! 文章目录 使用vue-cli创建vue3+ts项目 前言 ...

  4. 使用Vite创建Vue3+TS项目并整合Element Plus框架等一条龙服务

    记录一下使用Vite创建Vue3+TS项目以及整合Element Plus框架,还有Less.Pinia.Vue-router.monaco-editor等插件或组件. 一.使用Vite创建Vue3+ ...

  5. Vue项目中Echarts流向图迁徙图实现

    在数据可视化中,地图可视化是高频应用的一种.我们在一些新闻报道和商业杂志上,会经常看到运用地图来分析展示商业现象,这样的利用地图来反映和分析数据的形式叫数据地图.数据地图可以最直观的表达出数据之间的空 ...

  6. vue+ts项目中import图片时报错Cannot find module ‘xxx‘ or its corresponding type declarations

    TS项目中import图片时报错Cannot find module 'xxx' or its corresponding type declarations 在vue+ts项目中使用import的形 ...

  7. 用vite创建 vue3 ts项目

    先看看vite官网 这都2022年了,你肯定玩过vite + vue3 + ts项目吧 原先都是其他同事创建好项目,我直接上手 这次我自己来创建一下,在这里做一下记录 可以直接跟着官方教程走 http ...

  8. 在ts项目中接入live2d-widget.js , 在网页中展示二次元老婆

    原文链接: 在ts项目中接入live2d-widget.js , 在网页中展示二次元老婆 上一篇: tailwindcss 简单场景和官方案例 下一篇: git Submodule 将别人的模型文件通 ...

  9. vue项目中使用echarts-地图

    vue项目中使用echarts-地图 npm install echarts 在使用的页面或main.js中进行引用 import echarts from "echarts"; ...

最新文章

  1. (转载)Using GCC’s C++ Compiler
  2. Intel Realsense D435使用生成器初始化多个摄像头(c语言vector)
  3. 解析浏览器访问服务器 Servlet 应用程序的交互过程(Servlet 容器如何处理请求资源路径)
  4. 用户态和核心态的转换
  5. mongo DB for C#
  6. vue 代理设置 访问图片_详解Vue源码之数据的代理访问
  7. 一场由SameSite字段引发的前端悲剧
  8. linux定时任务总结。
  9. 哪些深度相机有python接口_用树莓派和YOLO打造一个深度学习照相机
  10. 加密模式 openssl sm4_OpenSSL/GmSSL 动态引擎
  11. Visual Studio 2019 离线安装包下载
  12. sublime text 3鼠标闪烁由竖线变为横线怎么处理?
  13. Cadence用于版图设计时芯片logo的制作
  14. vue元素实现动画过渡效果
  15. android 钉钉考勤日历,vue实现钉钉的考勤日历
  16. RS485_Modbus通讯笔记
  17. 【Captain America Sentinel of Liberty HD】美国队长:自由哨兵 v1.0.2
  18. 正确与错误、真理与谬误
  19. matlab中如何转动三维图_MATLAB小技巧之:绕任意空间轴旋转三维图形
  20. 国内外设计及素材站[转载]

热门文章

  1. mysql Access denied; you need (at least one of) the SUPER privilege(s) for this operation
  2. 枪炮、病毒与钢铁---读书笔记
  3. 事务隔离级别中脏读、不可重复读,幻读问题的解决
  4. sja1c语言,三菱A1SJ71UC24-R2手册A1SJ71UC24-R2硬件用户手册 - 广州凌控
  5. 数字图像的一阶微分和二阶微分
  6. Apache Flink 在快手万亿级数据的应用实践总结
  7. 全志V853开发板--构建编译
  8. 目前已确认 Windows 10 KB5015807 更新中存在的问题
  9. 一大波短视频应用 为何只有美拍这么火?
  10. OpenWRT路由器——网络打印服务器