Vue3Echarts写关于温湿度统计的好看折线图

在项目统计界面,我们离不开对Echarts的使用,接下来是我在做项目过程中做的一个关于温湿度统计的好看折线图,统计的是温度蓝色和湿度绿色,它们还会有告警和断电,分别用橘黄色和红色区分,以下是示例:

下载Echarts

//npm
npm install echarts --save

//淘宝镜像cnpm(安装速度快)
cnpm install echarts --save

//yarn
yarn add echarts

代码案例

<template>
    <div id="echartsOne" style="width: 100%;height: 100%;"></div>
</template>

<script setup>
    import * as echarts from 'echarts';
    import { onMounted,ref } from 'vue';
    onMounted(()=>{
        getEcharts();
    })
    const getEcharts = () => {
        let chartDom = document.getElementById("echartsOne");
        let myChart = echarts.init(chartDom);
        let wsdList = [{
      	createTime: "10:20",
      	humStatus: 0,
      	humidity: "59.4",
      	isOff: 0,
      	tempStatus: 0,
      	temperature: "28.8",
      }, {
      	createTime: "10:21",
      	humStatus: 0,
      	humidity: "59.4",
      	isOff: 1,
      	tempStatus: 0,
      	temperature: "28.8",
      }, {
      	createTime: "10:22",
      	humStatus: 0,
      	humidity: "59.4",
      	isOff: 0,
      	tempStatus: 1,
      	temperature: "28.8",
      }, {
      	createTime: "10:23",
      	humStatus: 0,
      	humidity: "59.4",
      	isOff: 0,
      	tempStatus: 0,
      	temperature: "28.8",
      }, {
      	createTime: "10:24",
      	humStatus: 1,
      	humidity: "59.4",
      	isOff: 0,
      	tempStatus: 0,
      	temperature: "28.8",
      }, {
      	createTime: "10:25",
      	humStatus: 0,
      	humidity: "59.4",
      	isOff: 1,
      	tempStatus: 0,
      	temperature: "28.8",
      }, {
      	createTime: "10:26",
      	humStatus: 1,
      	humidity: "59.4",
      	isOff: 0,
      	tempStatus: 0,
      	temperature: "28.8",
      },]
      let rq = []
      rq = wsdList.map(val => {
      	return val.createTime
      })
      let seriesArr = []
      let list = [{
      		name: "温度",
      		children: wsdList.map(val => {
      			let temp0 = val.tempStatus == 0 ? `rgb(68, 247, 227)` : `rgb(240, 128, 19)`;
      			return {
      				name: val.createTime,
      				value: val.isOff == 1 ? 6 : val.temperature,
      				isOff: val.isOff,
      				offTime: val.offTime ? val.offTime : "",
      				itemStyle: {
      					color: {
      						type: 'radial',
      						x: 0.5,
      						y: 0.5,
      						r: 0.5,
      						colorStops: [{
      								offset: 0,
      								color: val.isOff == 1 ? 'rgb(191, 53, 44)' : temp0, //中心颜色
      							},
      							{
      								offset: 0.4,
      								color: val.isOff == 1 ? 'rgb(191, 53, 44)' : temp0,
      							},
      							{
      								offset: 0.5,
      								color: '#ffffff00',
      							},
      							{
      								offset: 1,
      								color: '#ffffff00',
      							},
      						],
      					},
      					borderColor: val.isOff == 1 ? 'rgb(191, 53, 44)' : temp0,
      					borderWidth: 2,
      				},
      				lineStyle: {
      					type: "dashed",
      					color: val.isOff == 1 ? 'rgb(191, 53, 44)' : temp0,
      					width: 2,
      				},
      				label: {
      					show: false,
      					// show: val.isOff == 1 ? false : true
      				}
      			}
      		})
      	},
      	{
      		name: "湿度",
      		children: wsdList.map(val => {
      			let hum0 = val.humStatus == 0 ? `rgb(36, 214, 129)` : `rgb(240, 128, 19)`;
      			return {
      				name: val.createTime,
      				value: val.isOff == 1 ? 10 : val.humidity,
      				isOff: val.isOff,
      				itemStyle: {
      					color: {
      						type: 'radial',
      						x: 0.5,
      						y: 0.5,
      						r: 0.5,
      						colorStops: [{
      								offset: 0,
      								color: val.isOff == 1 ? 'rgb(191, 53, 44)' : hum0, //中心颜色
      							},
      							{
      								offset: 0.4,
      								color: val.isOff == 1 ? 'rgb(191, 53, 44)' : hum0,
      							},
      							{
      								offset: 0.5,
      								color: '#ffffff00',
      							},
      							{
      								offset: 1,
      								color: '#ffffff00',
      							},
      						],
      					},
      					borderColor: val.isOff == 1 ? 'rgb(191, 53, 44)' : hum0,
      					borderWidth: 2,
      				},
      				// lineStyle: {
      				//     type: "dashed",
      				//     color: val.isOff==1?'rgb(191, 53, 44)':hum0,
      				//     width: 2,
      				// },
      				label: {
      					show: false,
      					// show: val.isOff == 1 ? false : true,
      				}
      			}
      		})
      	}
      ]
      let colorArr = ["68, 247, 227", "36, 214, 129", "191, 53, 44"]
      list.forEach((val, index) => {
      	seriesArr.push({
      		yAxisIndex: val.name == "温度" ? 1 : 0,
      		xAxisIndex: 0,
      		name: val.name,
      		type: 'line',
      		data: val.children,
      		markLine: {
      			symbol: ['none', 'none'],
      			label: {
      				formatter: '{b}',
      				show: true,
      			},
      			data: [{
      				lineStyle: {
      					type: 'dashed',
      					color: "rgba(191, 53, 44,0)",
      					width: 2,
      				},
      				name: '断电',
      				label: {
      					color: "rgb(191, 53, 44)",
      					fontWeight: 600,
      					fontFamily: "黑体",
      					fontSize: 14,
      				},
      				yAxis: val.name == "湿度" ? 10 : 6,
      			}],
      		},
      		smooth: false,
      		symbolSize: 15,
      		symbol: 'circle',
      		showAllSymbol: true,
      		itemStyle: {
      			color: {
      				type: 'radial',
      				x: 0.5,
      				y: 0.5,
      				r: 0.5,
      				colorStops: [{
      						offset: 0,
      						color: `rgb(${colorArr[index]})`, //中心颜色
      					},
      					{
      						offset: 0.4,
      						color: `rgb(${colorArr[index]})`,
      					},
      					{
      						offset: 0.5,
      						color: '#ffffff00',
      					},
      					{
      						offset: 1,
      						color: '#ffffff00',
      					},
      				],
      			},
      			borderColor: `rgb(${colorArr[index]})`,
      			borderWidth: 2,
      		},
      		label: {
      			show: true,
      			position: val.name == "湿度" ? 'top' : "bottom",
      			textStyle: {
      				color: '#fff',
      				fontSize: 12
      			},
      			formatter: function(arr) {
      				return val.name == "温度" ? arr.value : arr.value + '%'
      			}
      		},
      		lineStyle: {
      			type: "dashed",
      			color: `rgb(${colorArr[index]})`,
      			width: 2,
      		}
      	})
      })
      let endNum = 5 / wsdList.length * 100
      let option = {
      	backgroundColor: "#06444a",
      	dataZoom: [{
      			type: 'inside',
      			start: 100 - (endNum > 100 ? 100 : endNum),
      			end: 100,
      			zoomLock: true, //定当前窗口,将缩放修改为左右偏移窗口
      		},
      		{
      			type: 'slider',
      			start: 100 - (endNum > 100 ? 100 : endNum),
      			end: 100,
      			zoomLock: true, //定当前窗口,将缩放修改为左右偏移窗口
      			height: 20,
      			showDetail: false,
      			brushSelect: false,
      		},
      	],
      	tooltip: {
      		trigger: 'axis',
      		axisPointer: {
      			lineStyle: {
      				color: '#ddd'
      			}
      		},
      		backgroundColor: 'rgba(255,255,255,1)',
      		padding: [5, 10],
      		textStyle: {
      			color: '#000',
      		},
      		formatter: function(params) {
      			return params[0].data.isOff == 1 ? `<div style='color:red;'>断电开始时间<br/>
                                  ${params[0].data.offTime.split(' ')[0]}<br/>
                                  ${params[0].data.offTime.split(' ')[1]}</div>` : `<div>
                              <div>${params[0].data.name}</div>
                              <div style='display:flex;align-items:center;'>
                                  温度:<b>${params[0].data.value}℃</b>
                              </div>
                              <div style='display:flex;align-items:center;'>
                                  湿度:<b>${params[1].data.value}%</b>
                              </div>
                          </div>`
      		}
      	},
      	legend: {
      		left: "center",
      		top: "0%",
      		textStyle: {
      			color: '#fff',
      			fontSize: 14,
      			fontWeight: 600
      		},
      		data: ["湿度", "温度", "告警", "断电"]
      	},
      	grid: {
      		left: '2%',
      		right: '3%',
      		bottom: '10%',
      		top: '10%',
      		containLabel: true
      	},
      	xAxis: [{
      		type: 'category',
      		data: rq,
      		axisTick: {
      			show: false
      		},
      		axisLine: {
      			lineStyle: {
      				color: '#bbdce0'
      			}
      		},
      		axisLabel: {
      			// margin: 10,
      			textStyle: {
      				fontSize: 12,
      				color: "#bbdce0",
      				fontWeight: 600
      			}
      		},
      		splitArea: {
      			show: true,
      			areaStyle: {
      				color: ["rgba(250,250,250,0.08)", "rgba(250,250,250,0)"]
      			}
      		}
      	}, {
      		type: 'category',
      		boundaryGap: false,
      		axisLabel: {
      			show: false
      		}
      	}],
      	yAxis: [{
      		name: "(%)",
      		type: 'value',
      		splitLine: {
      			show: true,
      			lineStyle: {
      				type: "dashed",
      				color: ['rgba(58, 129, 132,.6)']
      			}
      		},
      		axisTick: {
      			show: false
      		},
      		axisLine: {
      			show: true,
      			lineStyle: {
      				fontSize: 12,
      				color: '#bbdce0',
      			}
      		},
      		axisLabel: {
      			textStyle: {
      				fontSize: 12,
      				color: "#bbdce0",
      				fontWeight: 600
      			}
      		},
      		max: 100
      	}, {
      		name: "(℃)",
      		type: 'value',
      		splitLine: {
      			show: false,
      			lineStyle: {
      				type: "dashed",
      				color: ['#39868a']
      			}
      		},
      		axisTick: {
      			show: false
      		},
      		axisLine: {
      			show: true,
      			lineStyle: {
      				fontSize: 12,
      				color: '#bbdce0',
      			}
      		},
      		axisLabel: {
      			textStyle: {
      				fontSize: 12,
      				color: "#bbdce0",
      				fontWeight: 600
      			}
      		},
      		max: 60
      	}],
      	series: [...seriesArr, {
      		name: "告警",
      		type: 'line',
      		data: [],
      		smooth: false,
      		symbolSize: 15,
      		symbol: 'circle',
      		showAllSymbol: true,
      		itemStyle: {
      			color: {
      				type: 'radial',
      				x: 0.5,
      				y: 0.5,
      				r: 0.5,
      				colorStops: [{
      						offset: 0,
      						color: `rgb(240, 128, 19)`, //中心颜色
      					},
      					{
      						offset: 0.4,
      						color: `rgb(240, 128, 19)`,
      					},
      					{
      						offset: 0.5,
      						color: '#ffffff00',
      					},
      					{
      						offset: 1,
      						color: '#ffffff00',
      					},
      				],
      			},
      			borderColor: `rgb(240, 128, 19)`,
      			borderWidth: 2,
      		},
      		label: {
      			show: false
      		},
      		lineStyle: {
      			type: "dashed",
      			color: `rgb(240, 128, 19)`,
      			width: 2,
      		}
      	}, {
      		name: "断电",
      		type: 'line',
      		data: [],
      		smooth: false,
      		symbolSize: 15,
      		symbol: 'circle',
      		showAllSymbol: true,
      		itemStyle: {
      			color: {
      				type: 'radial',
      				x: 0.5,
      				y: 0.5,
      				r: 0.5,
      				colorStops: [{
      						offset: 0,
      						color: `rgb(191, 53, 44)`, //中心颜色
      					},
      					{
      						offset: 0.4,
      						color: `rgb(191, 53, 44)`,
      					},
      					{
      						offset: 0.5,
      						color: '#ffffff00',
      					},
      					{
      						offset: 1,
      						color: '#ffffff00',
      					},
      				],
      			},
      			borderColor: `rgb(191, 53, 44)`,
      			borderWidth: 2,
      		},
      		label: {
      			show: false
      		},
      		lineStyle: {
      			type: "dashed",
      			color: `rgb(191, 53, 44)`,
      			width: 2,
      		}
      	}]
      };
        myChart.setOption(option);
    }
</script>

运行结果

本文来自互联网用户投稿,该文观点仅代表作者本人,不代表本站立场。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如若转载,请注明出处:http://www.mfbz.cn/a/769166.html

如若内容造成侵权/违法违规/事实不符,请联系我们进行投诉反馈qq邮箱809451989@qq.com,一经查实,立即删除!

相关文章

CesiumJS【Basic】- #056 绘制纹理填充多边形(Entity方式)-使用shader

文章目录 绘制纹理填充多边形(Entity方式)-使用shader1 目标2 代码2.1 main.ts绘制纹理填充多边形(Entity方式)-使用shader 1 目标 使用Entity方式绘制绘制纹理填充多边形 - 使用shader 2 代码 2.1 main.ts import * as Cesium from cesium;const viewer = new Cesium…

Linux系统中交叉编译opencv库

目标&#xff1a;将opencv进行交叉编译&#xff0c;使其能在rk3326板子上运行使用。 环境&#xff1a; ubuntu&#xff1a;18.04 opencv:4.5.4 opencv源码从挂网下载&#xff1a;opencv源码下载地址 交叉编译链&#xff1a;gcc-arm-10.3-linux-gun 一.环境准备 1.交叉编译链我…

【RT摩拳擦掌】如何构建RT AVB switchendpoint平台

【RT摩拳擦掌】如何构建RT AVB switch&endpoint平台 一&#xff0c;文档简介二&#xff0c;平台构建2.1 软硬件情况2.2 配置RT1170 AVB端点2.2.1 1块MIMXRT1170开发板做talker配置2.2.2 2块MIMXRT1170开发板做listener配置 2.3 AVB Switch 配置2.3.1 MOTU AVB Switch2.3.2 …

Ansys Zemax|场曲跟畸变图的前世今生

实现 OpticStudio通过在X和Y方向&#xff08;弧矢和子午方向&#xff09;的傍轴光线追踪确定近轴图像平面的Z坐标&#xff0c;并测量该近轴焦平面与系统图像平面的Z坐标之间的距离。 切向数据是沿Z轴从图像平面到近轴图像平面在切向&#xff08;YZ&#xff09;平面测量的距离…

【LeetCode刷题】3099.哈沙德数

题目链接 3099. 哈沙德数 - 力扣&#xff08;LeetCode&#xff09; 实现代码 int sumOfTheDigitsOfHarshadNumber(int x) {int sum 0;for(int temp x; temp; temp / 10)sum temp % 10;return x%sum ? -1 : sum; }

魔行观察-AI数据分析>>勒泰中心购物中心

摘要 本报告基于 魔行观察 搜集整理的数据&#xff0c;对勒泰中心购物中心的营业状态、商户构成、业态分布以及消费者评价进行了详细分析。 商场概览 勒泰中心是一个正常营业的购物中心&#xff0c;自2013年开业以来&#xff0c;已成为当地居民和游客的重要购物和休闲场所。…

3D一览通优化供应链协同,加速产品设计研发和上市

在现代企业管理中&#xff0c;供应链管理无疑占据着举足轻重的地位。它不仅是企业资源优化配置的基石&#xff0c;更是企业降低成本、提高效率、满足客户需求、保持市场竞争力的关键环节。对于工业企业来说&#xff0c;供应链的高效运作尤其重要。 然而&#xff0c;在实际操作…

一篇文章用python GUI构建学生管理系统

引言 通过使用Python&#xff0c;我们可以利用其简洁和功能强大的特性&#xff0c;结合Tkinter提供的GUI开发能力&#xff0c;快速构建一个直观且易于使用的学生管理系统。 准备工作 在开始之前&#xff0c;确保你的开发环境中已经安装了 PythonTkinter库 安装完成后&…

SQLServer:从数据类型 varchar 转换为 numeric 时出错。

1.工作要求 计算某两个经纬度距离 2.遇到问题 从数据类型 varchar 转换为 numeric 时出错。 3.解决问题 项目版本较老&#xff0c;使用SQLServer 2012 计算距离需执行视图&#xff0c;如下&#xff1a; SET QUOTED_IDENTIFIER ON SET ANSI_NULLS ON GO ALTER view vi_ord…

2024年迄今最热门的10款网络安全工具和产品

今年上半年&#xff0c;利用生成式人工智能&#xff08;GenAI&#xff09;的网络安全工具继续激增。许多供应商正在利用GenAI的功能来自动化安全运营中心&#xff08;SOC&#xff09;的工作&#xff0c;特别是在自动化日常活动方面&#xff0c;如收集威胁信息和自动创建查询。 …

Elasticsearch (1):ES基本概念和原理简单介绍

Elasticsearch&#xff08;简称 ES&#xff09;是一款基于 Apache Lucene 的分布式搜索和分析引擎。随着业务的发展&#xff0c;系统中的数据量不断增长&#xff0c;传统的关系型数据库在处理大量模糊查询时效率低下。因此&#xff0c;ES 作为一种高效、灵活和可扩展的全文检索…

Profibus DP主站转Modbus网关连接伺服与电机通讯

在工业自动化领域&#xff0c;将Profibus DP主站转Modbus网关&#xff08;XD-MDPBM20&#xff09;用于连接伺服与电机通讯是一种常见且重要的应用方式。当使用Profibus DP主站转Modbus网关&#xff08;XD-MDPBM20&#xff09;连接伺服与电机进行通讯时&#xff0c;可以参考以下…

强连通分量

强连通分量 强连通定义 有向图 G G G 的强连通是指 G G G 中任意两个节点都可以直接或间接到达。 下方两幅图都是强连通。一个特殊一点&#xff0c;任意两点都可以直接到达&#xff1b;一个则是最常见的强连通图。 特殊强连通图&#xff0c;任意两点都可以直接到达 常见的…

虚拟机启动失败 请进行修复 关闭hyper-v

场景 win11开启夜神模拟器时弹出此提示。点击关闭hyper-v并重启电脑后仍然不行。 解决方法 关闭 Windows安全中心 的 内存完整性 后重启电脑恢复正常。 补充 由于我这里除了会用到夜神模拟器&#xff0c;还会用到docker&#xff0c;而docker又依赖hyper-v&#xff0c;不…

YOLOv5初学者问题——用自己的模型预测图片不画框

如题&#xff0c;我在用自己的数据集训练权重模型的时候&#xff0c;在训练完成输出的yolov5-v5.0\runs\train\exp2目录下可以看到&#xff0c;在训练测试的时候是有输出描框的。 但是当我引用训练好的best.fangpt去进行预测的时候&#xff0c; 程序输出的图片并没有描框。根据…

【小白教学】-- 安装Ubuntu-20.04系统

下载 Ubuntu-20.04 镜像 具体如何下载镜像&#xff0c;请移驾我上一篇文章。使用清华大学开源镜像站下载。https://zhuanlan.zhihu.com/p/706444837 制作 Ubuntu-20.04 系统盘 安装软件 UltralSO 开始制作系统盘 第一步&#xff0c;插入一个 u 盘&#xff0c;启动软件&#x…

PO模式登录测试

项目实践 登陆项目测试 get_driver import page from selenium import webdriverclass GetDriver:driver Noneclassmethoddef get_driver(cls):if cls.driver is None:cls.driver webdriver.Edge()cls.driver.maximize_window()cls.driver.get(page.url)return cls.drivercl…

关于批量采集1688商品主图及链接的方式:软件采集/1688官方API接口数据采集

关于批量采集&#xff0c;我们通常用到的是软件 采集&#xff0c;或者通过1688官方API数据采集的形式&#xff1a;用户输入一组1688商品ID&#xff0c;一行一个&#xff0c;流程会自动逐个打开对应的1688商品详情页&#xff0c;采集主图的所有链接。 结果保存为表格的一行&…

Linux运维之管道符、重定向与环境变量

前言&#xff1a;本博客仅作记录学习使用&#xff0c;部分图片出自网络&#xff0c;如有侵犯您的权益&#xff0c;请联系删除 目录 一、输入输出重定向 二、管道命令符 三、命令行的通配符 四、常用的转义字符 五、重要的环境变量 致谢 一、输入输出重定向 输入重定向是…

【Python+微信小程序】学生考勤签到系统(已开源)

1. 简介 &#x1f61d; 这个项目是一款基于微信小程序和Flask框架开发的应用&#xff0c;旨在帮助学校管理学生的考勤和课程信息。系统通过集成数据库管理、API开发以及前后端交互&#xff0c;实现了便捷的学生考勤记录、课程表管理和教师交互功能。其主要特点包括&#xff1a…