uniapp 使用renderjs引入echarts
效果图:
1.1renderjs引入echarts
组件zmui-echarts.vue:
<template><view class="zmui-echarts" :prop="option" :change:prop="echarts.delay"></view>
</template><script>export default {name: 'zmuiEcharts',props: {option: {type: Object,required: true}}}
</script>//使用renderjs 就让app拥有类似有.HTML文件的环境 能直接挂载.js的能力
<script module="echarts" lang="renderjs"> export default {data() {return {timeoutId: null,chart: null}},mounted() {if (typeof window.echarts === 'object') {this.init()} else {// 动态引入类库const script = document.createElement('script') //创建个标签script.src = './static/echarts.min.js' //引入echarts.min.jsscript.onload = this.initdocument.head.appendChild(script) //全局挂载echarts.min.js}},methods: {/*** 初始化echarts*/init() {// 根据id初始化图表this.chart = echarts.init(this.$el)this.update(this.option)},/*** 防抖函数,500毫秒内只运行最后一次的方法* @param {Object} option*/delay(option) {if (this.timeoutId) {clearTimeout(this.timeoutId)this.timeoutId = null}this.timeoutId = setTimeout(() => {this.update(option)}, 500)},/*** 监测数据更新* @param {Object} option*/update(option) {console.log('option', option)if (this.chart) {// 因App端,回调函数无法从renderjs外传递,故在此自定义设置相关回调函数if (option) {// tooltipif (option.tooltip) {// 判断是否设置tooltip的位置if (option.tooltip.positionStatus) {option.tooltip.position = this.tooltipPosition()}// 判断是否格式化tooltipif (option.tooltip.formatterStatus) {option.tooltip.formatter = this.tooltipFormatter(option.tooltip.formatterUnit, option.tooltip.formatFloat2,option.tooltip.formatThousands)}}// legendif (option.legend) {console.log('option.legend', option.legend)if (Object.prototype.toString.call(option.legend) == '[object Array]') {for (let i in option.legend) {if (option.legend[i].formatterStatus) {option.legend[i].formatter = this.legendFormatter(option.legend[i].formatterType, option.legend[i].formatterArr)}}console.log(12)} else {if (option.legend.formatterStatus) {console.log(56)// option.legend.formatter = this.legendFormatter(option.legend.formatterType, option.legend.formatterArr)// option.legend.formatter = function(value) {// return '1'// }}console.log(34)}}// y轴if (option.yAxis) {if (option.yAxis.axisLabel) {if (option.yAxis.axisLabel.formatterStatus) {option.yAxis.axisLabel.formatter = this.yAxisFormatter(option.yAxis.axisLabel.formatterData)}}if (option.yAxis[0].axisLabel.water) {let currentChooseName = option.yAxis[0].axisLabel.water.currentChooseNamelet name = option.yAxis[0].axisLabel.water.nameconsole.log('name========>', name,currentChooseName)option.yAxis[0].axisLabel.formatter = function(value) {let level = nullif (currentChooseName == '西铝饮用水' || currentChooseName == '和尚山') {if (name == 'CODMn') {switch (value) {case 2:level = 2.0;break;case 4:level = 4.0;break;case 6:level = 6.0;break;case 10:level = 10.0;break;}return level;}else if (name == 'TP') {switch (value) {case 0.02:level = 0.02;break;case 0.1:level = 0.1;break;case 0.2:level = 0.2;break;case 0.3:level = 0.3;break;}return level;}else if (name == 'DO') {switch (value) {case 7.5:level = 7.5;break;case 6:level = 6.0;break;case 5:level = 5.0;break;case 3:level = 3.0;break;}return level;}else if (name == 'TN') {switch (value) {case 0.2:level = 0.2;break;case 0.5:level = 0.5;break;case 1:level = 1.0;break;case 1.5:level = 1.5;break;}return level;} else if (name == 'NH3-N') {switch (value) {case 0.15:level = 0.15;break;case 0.5:level = 0.5;break;case 1:level = 1.0;break;case 1.5:level = 1.5;break;}return level;}}else if(currentChooseName !== '西铝饮用水' || currentChooseName !== '和尚山') {if (name == 'CODMn') {switch (value) {case 4:level = 4.0;break;case 6:level = 6.0;break;case 10:level = 10.0;break;case 15:level = 15.0;break;}return level;}else if (name == 'TP') {switch (value) {case 0.1:level = 0.1;break;case 0.2:level = 0.2;break;case 0.3:level = 0.3;break;case 0.4:level = 0.4;break;}return level;} else if (name == 'DO') {switch (value) {case 6:level = 6.0;break;case 5:level = 5.0;break;case 3:level = 3.0;break;case 2:level = 2.0;break;}return level;}else if (name == 'TN') {switch (value) {case 0.5:level = 0.5;break;case 1:level = 1.0;break;case 1.5:level = 1.5;break;case 2:level = 2.0;break;}return level;} else if (name == 'NH3-N') {switch (value) { case 0.5:level = 0.5;break;case 1:level = 1.0;break;case 1.5:level = 1.5;break;case 2:level = 2.0;break;}return level;}} }}}// 颜色渐变if (option.series) {for (let i in option.series) {let linearGradient = option.series[i].linearGradientif (option.series[i].axisLabel && option.series[i].axisLabel.formatterText) {option.series[i].axisLabel.formatter = function(value) {if (value === 0) {return '0 \n 健康';} else if (value === 1) {return '50 \n 优';} else if (value === 2) {return '100 \n 良';} else if (value === 3) {return '150 \n 轻度';} else if (value === 4) {return '200 \n 中度';} else if (value === 5) {return '300 \n 重度';} else if (value === 6) {return '500 \n 严重';}}}if (linearGradient) {option.series[i].color = new echarts.graphic.LinearGradient(linearGradient[0], linearGradient[1],linearGradient[2], linearGradient[3], linearGradient[4])}if (option.series[i].itemStyle) {if (option.series[i].itemStyle.normal) {if (option.series[i].itemStyle.normal.formatterColor) {option.series[i].itemStyle.normal.color = this.colorFormatter(option.series[i].itemStyle.normal.formatterType,option.series[i])}}}if (option.series[i].markLine) {if (option.series[i].markLine.label) {if (option.series[i].markLine.label.normal) {if (option.series[i].markLine.label.normal.formatterLabel) {option.series[i].markLine.label.normal.formatter = this.labelFormatter(option.series[i].markLine.label.normal.formatterType, option.series[i].markLine.label.normal.formatterValue)}}}}}}}console.log(option)this.chart.clear() // 这个不要删掉哟,不然切换不同图形的时候会有bug// 设置新的optionthis.chart.setOption(option, option.notMerge)}},waterFormatterYAxis (value) {/* let name = nullswitch (value) {case 2:name = 2.0;break;case 4:name = 4.0;break;case 6:name = 6.0;break;case 10:name = 10.0;break;} */console.log('value', value)// return name;},/*** 设置tooltip的位置,防止超出画布*/tooltipPosition() {return (point, params, dom, rect, size) => {// 其中point为当前鼠标的位置,size中有两个属性:viewSize和contentSize,分别为外层div和tooltip提示框的大小let x = point[0]let y = point[1]let viewWidth = size.viewSize[0]let viewHeight = size.viewSize[1]let boxWidth = size.contentSize[0]let boxHeight = size.contentSize[1]let posX = 0 // x坐标位置let posY = 0 // y坐标位置if (x >= boxWidth) { // 左边放的下posX = x - boxWidth - 1}if (y >= boxHeight) { // 上边放的下posY = y - boxHeight - 1}return [posX, posY]}},/*** tooltip格式化* @param {Object} unit 数值后的单位* @param {Object} formatFloat2 是否保留两位小数* @param {Object} formatThousands 是否添加千分位*/tooltipFormatter(unit, formatFloat2, formatThousands) {return params => {if (Array.isArray(params)) {var params = params[0]// #ifdef H5var result = params.data.fullDate + '/n' + params.seriesName + ":" + params.data.value// #endif// #ifdef APP-PLUSvar result = params.data.fullDate + '</br>' + params.seriesName + ":" + params.data.value// #endif} else {// #ifdef H5var result = params.data.fullDate + '/n' + params.seriesName + ":" + params.data.value// #endif// #ifdef APP-PLUSvar result = params.data.fullDate + '</br>' + params.seriesName + ":" + params.data.value// #endif}return result}},/*** 保留两位小数* @param {Object} value*/formatFloat2(value) {let temp = Math.round(parseFloat(value) * 100) / 100let xsd = temp.toString().split('.')if (xsd.length === 1) {temp = (isNaN(temp) ? '0' : temp.toString()) + '.00'return temp}if (xsd.length > 1) {if (xsd[1].length < 2) {temp = temp.toString() + '0'}return temp}},/*** 添加千分位* @param {Object} value*/formatThousands(value) {if (value === undefined || value === null) {value = ''}if (!isNaN(value)) {value = value + ''}let re = /\d{1,3}(?=(\d{3})+$)/glet n1 = value.replace(/^(\d+)((\.\d+)?)$/, function(s, s1, s2) {return s1.replace(re, '$&,') + s2})return n1},/*** Y轴格式化* @param {Object} data*/yAxisFormatter(data) {return params => {let result = []for (let i in data) {if (params == i) {result.push(data[i])}}return result}},/*** legend 格式* @param {Object} Type* @param {Object} Arr*/legendFormatter(Type, Arr) {console.log('Arr', Arr)return params => {let result = ""var total = 0;for (var i = 0, l = Arr.length; i < l; i++) {total += Arr[i].value;}let res = Arr.filter(v => v.name === params)let val = res[0].valuelet precent=((val/total)*100).toFixed(2) + '%'// #ifdef H5result = params +"("+ val+"件)"// #endif// #ifdef APP-PLUSresult = params +"("+ val+"件)"// #endifreturn result}},/*** 颜色设置* @param {Object} Type*/colorFormatter(Type,series) {let value =0;return params => {//如果series 里面包含aqiData 数据 按AQI 的值来渲染颜色let value =params.value;if(series['aqiData']!=null){value =series['aqiData'][params.dataIndex];} let result = ""if (Type === 'one') {result = "rgb(126,0,35)"if (value > 0 && value < 51) {result = "#00e400"} else if (value >= 51 && value < 101) {result = "#ffff00"} else if (value>= 101 && value < 151) {result = "#ff7e00"} else if (value >= 151 && value < 201) {result = "#ff0000"} else if (value >= 201 && value < 301) {result = "#7e0023"}}return result}},/*** 标记线* @param {Object} Type* @param {Object} Value*/labelFormatter(Type, Value) {return params => {let result = ""if (Type === 'one') {result = Value}return result}},}}
</script><style scoped>.zmui-echarts {width: 100%;height: 100%;}
</style>
2.使用<zmuiEcharts :option="echartOptions"></zmuiEcharts>
import zmuiEcharts from '@/components/zmui-echarts/zmui-echarts.vue'
components: {zmuiEcharts},
<zmuiEcharts :option="echartOptions"></zmuiEcharts>export default {data(){return{echartOptions: {backgroundColor: '#ffffff',title: {text: 'mg/L',textStyle: {fontSize: 12,fontWeight: 'normal',color: '#858585', //标题颜色},top: 0,left: '4%',},tooltip: {show: false// axisPointer: {// type: "axis",// textStyle: {// color: "#000"// }// },// formatter: (data) => {// // 可以自定义文字和样式,用行内样式,数据包含在data参数中// let text = ` ${data.name}:${data.value}`// return text// }},grid: {top: "5%",right: "3%",bottom: '13%',},xAxis: [{data: [],margin: 20,interval: 0,rotate: 40,color: '#858585',textStyle: {fontSize: 12},axisLine: {lineStyle: {color: '#858585',}},axisTick: {show: true},}],axisLine: {show: false,lineStyle: {color: '#858585', //y轴颜色}},axisTick: {show: false},splitLine: {show: false},dataZoom: [{"show": true,"height": 8,"xAxisIndex": [0],bottom: '0%',start: 0,end: 6,handleIcon: "M-292,322.2c-3.2,0-6.4-0.6-9.3-1.9c-2.9-1.2-5.4-2.9-7.6-5.1s-3.9-4.8-5.1-7.6c-1.3-3-1.9-6.1-1.9-9.3c0-3.2,0.6-6.4,1.9-9.3c1.2-2.9,2.9-5.4,5.1-7.6s4.8-3.9,7.6-5.1c3-1.3,6.1-1.9,9.3-1.9c3.2,0,6.4,0.6,9.3,1.9c2.9,1.2,5.4,2.9,7.6,5.1s3.9,4.8,5.1,7.6c1.3,3,1.9,6.1,1.9,9.3c0,3.2-0.6,6.4-1.9,9.3c-1.2,2.9-2.9,5.4-5.1,7.6s-4.8,3.9-7.6,5.1C-285.6,321.5-288.8,322.2-292,322.2z",handleSize: "130%",handleStyle: {color: "#fff",shadowColor: "#B1B5B9",shadowBlur: 5,},backgroundColor: "#DEE3F4",fillerColor: "#008efe",endValue: 5,},{"type": "inside","show": true,"height": 15,"start": 1,"end": 35}],yAxis: [{type: 'value',min: 0,max: 0,interval: 0.01,name: 'nj',nameTextStyle: {color: '#ffffff'},axisLine: {show: true},axisTick: {show: false},splitLine: {show: false,},axisLabel: {color: '#858585',textStyle: {fontSize: 13},formatter: function(value1) {return value1;},water: {name: 'water',code: 'code'},},}],series: [{label: {normal: {show: true,color: '#333',position: 'top',}},name: 'nj',type: 'bar',data: [],barWidth: '8px',itemStyle: {normal: {formatterColor: true,formatterType: "one",}},}]}}}
}
相关文章:

uniapp 使用renderjs引入echarts
效果图: 1.1renderjs引入echarts 组件zmui-echarts.vue: <template><view class"zmui-echarts" :prop"option" :change:prop"echarts.delay"></view> </template><script>export defaul…...

hr最讨厌这6种应届生简历❌
用求职方法,让你变成offer收割机,是我的责任❗ 简历写得好,面试少不了。最近很多应届生找龙猫帮看简历,我发现很多应届生是真不会写简历啊。 有的简历排版花里胡哨,有的自我评价千篇一律,有的实习经历太过…...

【Linux笔记】文件系统与软硬链接
一、文件系统概述 1.1、先来聊一聊“磁盘” 在讲解文件系统之前,我觉得有必要先聊一下“磁盘”,因为我觉得如果弄懂了磁盘的存储原理,大家可能更容易理解文件系统是怎么管理数据的,并且理解计算机是怎么将磁盘抽象到文件系统的。…...

vue3(笔记)
组合式Api setup-----相当于beforeCreate, create生命周期 reactive–定义状态 对象形式 响应式原理 toRefs— Pinia (只有state、getters和actions) 更加简洁的语法,完美支持Vue3的Composition api 和 对TypesCcript的完美支持...

Java面向对象 this
this 在Java中,this 是一个特殊的引用变量,它引用了当前对象实例。当在类的非静态方法或构造方法中使用时,this 关键字指代当前的对象实例。它经常用于区分对象的成员变量和局部变量,或者调用其他重载的方法。 以下是一些使用 t…...

阿里云游戏服务器租用价格表,2024最新报价
阿里云游戏服务器租用价格表:4核16G服务器26元1个月、146元半年,游戏专业服务器8核32G配置90元一个月、271元3个月,阿里云服务器网aliyunfuwuqi.com分享阿里云游戏专用服务器详细配置和精准报价: 阿里云游戏服务器租用价格表 阿…...

2-1 动手学深度学习v2-Softmax回归-笔记
回归 VS 分类 回归估计一个连续值分类预测一个离散类别 从回归到多类分类 回归 单连续数值输出输出的区间:自然区间 R \mathbb{R} R损失:跟真实值的区别 分类 通常多个输出(这个输出的个数是等于类别的个数)输出的第 i i i…...

laravel distinct查询问题,laravel子查询写法
直接调用后,count查询会和实际查询的数据对不上,count还是查询全部数据,而实际的列表是去重的。 给distinct加上参数,比如去重的值的id,就加id。 另一种写法是使用group by id 子查询。 sql语句: selec…...

AI助力农作物自动采摘,基于DETR(DEtection TRansformer)开发构建作物生产场景下番茄采摘检测计数分析系统
去年十一那会无意间刷到一个视频展示的就是德国机械收割机非常高效自动化地24小时不间断地在超广阔的土地上采摘各种作物,专家设计出来了很多用于采摘不同农作物的大型机械,看着非常震撼,但是我们国内农业的发展还是相对比较滞后的࿰…...
C语言——字符串大小写互换
前言: 在C语言中,大小写字母相互转换是一个常见的操作。本文将详细介绍C语言中实现大小写字母相互转换的各种方法,并附上代码示例。 目录 一、使用tolower()和toupper()函数 二、使用位操作 三、使用字符串操作函数 一、使用tolower()和t…...

macOS的设置与常用软件(含IntelliJ IDEA 2023.3.2 Ultimate安装,SIP的关闭与开启)
目录 1 系统设置1.1 触控板1.2 键盘 2 软件篇2.1 [科学上网](https://justmysocks5.net/members/)2.1 [安装Chrome浏览器](https://www.google.cn/chrome/index.html)2.2 [安装utools](https://www.u.tools)2.3 [安装搜狗输入法](https://shurufa.sogou.com/)2.4 [安装snipaste…...

http伪造本地用户字段系列总结
本篇记录了http伪造本地用户的多条字段,便于快速解决题目 用法举例: 直接把伪造本地用户的多个字段复制到请求头中,光速解决部分字段被过滤的问题。 Client-IP: 127.0.0.1 Forwarded-For-Ip: 127.0.0.1 Forwarded-For: 127.0.0.1 Forwarded…...

Hadoop-IDEA开发平台搭建
1.安装下载Hadoop文件 1)hadoop-3.3.5 将下载的文件保存到英文路径下,名称一定要短。否则容易出问题; 2)解压下载下来的文件,配置环境变量 3)我的电脑-属性-高级设置-环境变量 4.详细配置文件如下&#…...
block任务块、rescue和always、loop循环、role角色概述、role角色应用、ansible-vault、sudo提权、特殊的主机清单变量
任务块 可以通过block关键字,将多个任务组合到一起可以将整个block任务组,一起控制是否要执行 # 如果webservers组中的主机系统发行版是Rocky,则安装并启动nginx[rootpubserver ansible]# vim block1.yml---- name: block taskshosts: webse…...

Qt:QFileDialog
目录 一、介绍 二、功能 三、具体事例 1、将某个界面保存为图片,后缀名可选PNG、JPEG、SVG等 一、介绍 QFileDialog提供了一个对话框,允许用户选择文件或者目录,也允许用户遍历文件系统,用以选择一个或多个文件或者目录。 QF…...

我的QQ编程学习群
欢迎大家加入我的QQ编程学习群。 群号:950365002 群里面有许多的大学生大佬,有编程上的疑惑可以随时问,也可以聊一些休闲的东西。 热烈欢迎大家加入!! 上限:150人。...

【C++】类与对象(四)——初始化列表|explicit关键字|static成员|友元|匿名对象
前言: 初始化列表,explicit关键字,static成员,友元,匿名对象 文章目录 一、构造函数的初始化列表1.1 构造函数体内赋值1.2 初始化列表 二、explicit关键字三、static成员四、友元4.1 友元函数4.2 友元类 五、内部类六、…...

ChatGPT高效提问—prompt常见用法
ChatGPT高效提问—prompt常见用法 1.1 角色扮演 prompt最为常见的用法是ChatGPT进行角色扮演。通常我们在和ChatGPT对话时,最常用的方式是一问一答,把ChatGPT当作一个单纯的“陪聊者”。而当我们通过prompt为ChatGPT赋予角色属性后,即使…...

使用vite创建vue+ts项目,整合常用插件(scss、vue-router、pinia、axios等)和配置
一、检查node版本 指令:node -v 为什么要检查node版本? Vite 需要 Node.js 版本 18,20。然而,有些模板需要依赖更高的 Node 版本才能正常运行,当你的包管理器发出警告时,请注意升级你的 Node 版本。 二、创…...

泛型、Trait 和生命周期(上)
目录 1、提取函数来减少重复 2、在函数定义中使用泛型 3、结构体定义中的泛型 4、枚举定义中的泛型 5、方法定义中的泛型 6、泛型代码的性能 每一门编程语言都有高效处理重复概念的工具。在 Rust 中其工具之一就是 泛型(generics)。泛型是具体类型…...
linux 下常用变更-8
1、删除普通用户 查询用户初始UID和GIDls -l /home/ ###家目录中查看UID cat /etc/group ###此文件查看GID删除用户1.编辑文件 /etc/passwd 找到对应的行,YW343:x:0:0::/home/YW343:/bin/bash 2.将标红的位置修改为用户对应初始UID和GID: YW3…...

令牌桶 滑动窗口->限流 分布式信号量->限并发的原理 lua脚本分析介绍
文章目录 前言限流限制并发的实际理解限流令牌桶代码实现结果分析令牌桶lua的模拟实现原理总结: 滑动窗口代码实现结果分析lua脚本原理解析 限并发分布式信号量代码实现结果分析lua脚本实现原理 双注解去实现限流 并发结果分析: 实际业务去理解体会统一注…...

论文笔记——相干体技术在裂缝预测中的应用研究
目录 相关地震知识补充地震数据的认识地震几何属性 相干体算法定义基本原理第一代相干体技术:基于互相关的相干体技术(Correlation)第二代相干体技术:基于相似的相干体技术(Semblance)基于多道相似的相干体…...

AirSim/Cosys-AirSim 游戏开发(四)外部固定位置监控相机
这个博客介绍了如何通过 settings.json 文件添加一个无人机外的 固定位置监控相机,因为在使用过程中发现 Airsim 对外部监控相机的描述模糊,而 Cosys-Airsim 在官方文档中没有提供外部监控相机设置,最后在源码示例中找到了,所以感…...
纯 Java 项目(非 SpringBoot)集成 Mybatis-Plus 和 Mybatis-Plus-Join
纯 Java 项目(非 SpringBoot)集成 Mybatis-Plus 和 Mybatis-Plus-Join 1、依赖1.1、依赖版本1.2、pom.xml 2、代码2.1、SqlSession 构造器2.2、MybatisPlus代码生成器2.3、获取 config.yml 配置2.3.1、config.yml2.3.2、项目配置类 2.4、ftl 模板2.4.1、…...

云原生安全实战:API网关Kong的鉴权与限流详解
🔥「炎码工坊」技术弹药已装填! 点击关注 → 解锁工业级干货【工具实测|项目避坑|源码燃烧指南】 一、基础概念 1. API网关(API Gateway) API网关是微服务架构中的核心组件,负责统一管理所有API的流量入口。它像一座…...

RabbitMQ入门4.1.0版本(基于java、SpringBoot操作)
RabbitMQ 一、RabbitMQ概述 RabbitMQ RabbitMQ最初由LShift和CohesiveFT于2007年开发,后来由Pivotal Software Inc.(现为VMware子公司)接管。RabbitMQ 是一个开源的消息代理和队列服务器,用 Erlang 语言编写。广泛应用于各种分布…...

2025年渗透测试面试题总结-腾讯[实习]科恩实验室-安全工程师(题目+回答)
安全领域各种资源,学习文档,以及工具分享、前沿信息分享、POC、EXP分享。不定期分享各种好玩的项目及好用的工具,欢迎关注。 目录 腾讯[实习]科恩实验室-安全工程师 一、网络与协议 1. TCP三次握手 2. SYN扫描原理 3. HTTPS证书机制 二…...
Caliper 配置文件解析:fisco-bcos.json
config.yaml 文件 config.yaml 是 Caliper 的主配置文件,通常包含以下内容: test:name: fisco-bcos-test # 测试名称description: Performance test of FISCO-BCOS # 测试描述workers:type: local # 工作进程类型number: 5 # 工作进程数量monitor:type: - docker- pro…...

什么是VR全景技术
VR全景技术,全称为虚拟现实全景技术,是通过计算机图像模拟生成三维空间中的虚拟世界,使用户能够在该虚拟世界中进行全方位、无死角的观察和交互的技术。VR全景技术模拟人在真实空间中的视觉体验,结合图文、3D、音视频等多媒体元素…...