uniapp 如何使用echarts 以及解决tooltip自定义不生效;dataZoom报错问题

本文主要是介绍uniapp 如何使用echarts 以及解决tooltip自定义不生效;dataZoom报错问题,希望对大家解决编程问题提供一定的参考价值,需要的开发者们随着小编来一起学习吧!

使用的是echarts-for-wx插件;
正常写法案例:给tooltip数值加个%

<template><view><uni-ec-canvas class="uni-ec-canvas"id="uni-ec-canvas"ref="canvas"canvas-id="uni-ec-canvas":ec="ec"></uni-ec-canvas></view>
</template>
<script>
// 此处将路径替换为你放置该组件的路径  
import uniEcCanvas from './uni-ec-canvas/ec-canvas.vue'  export default{data(){return {ec:{options:{} //echart 配置项}}},components:{uniEcCanvas},mounted(){this.initChart()},methods:{initChart(){this.ec.option={//其他配置项我就不写了,只展示tooltiptooltip: {trigger: 'axis',confine: true, //提示框限制在图形内axisPointer: {type: 'line',axis: 'auto', // 指示器的坐标轴。 snap: true, // 坐标轴指示器是否自动吸附到点上},textStyle: {// color: "#fff" //设置文字颜色},padding: 5, // 提示框浮层内边距,formatter: (params)=> {var html = params[0].name + '\n';//资金使用率添加%html +=params[0].marker +params[0].seriesName +':' +params[0].value +'%'return html;}// backgroundColor: '#ee6461',},}this.$refs.canvas.init();}}
}
</script>
// 这里一定要注意 设置该组件宽高 以及display:block来确保canvas初始化的时候是有宽高的
<style>
.uni-ec-canvas{width:100%;height:100%;display:block;
}
</style>

这样的写法formatter自定义是不会生效的;
想要自定义生效的正确写法

this.$refs['canvas'].ec.option={tooltip: {trigger: 'axis',confine: true, //提示框限制在图形内axisPointer: {type: 'line',axis: 'auto', // 指示器的坐标轴。 snap: true, // 坐标轴指示器是否自动吸附到点上},padding: 5, // 提示框浮层内边距,formatter: (params)=> {var html = params[0].name + '\n';//资金使用率添加%html +=params[0].marker +params[0].seriesName +':' +params[0].value +'%'return html;}},
}

在这里插入图片描述
顺带提一嘴在开发工具上看会有echarts层级太高遮挡显示层问题;这个问题不必理会,真机上显示是正常的
在这里插入图片描述
再使用dataZoom组件的时候会报错e.preventDefault is not a function
解决方法
找到echarts组件的vue文件,我的是 uni-ec-canvas.vue

//在触摸事件加上preventDefault: () => {},
stopImmediatePropagation: () => {},
stopPropagation: () => {}

touchStart(e) {if (this.ec.stopTouchEvent) {e.preventDefault();e.stopPropagation();return;}this.$emit("touchstart", e);if (this.$curChart && e.touches.length > 0) {var touch = e.touches[0];var handler = this.$curChart.getZr().handler;if (handler) {handler.dispatch("mousedown", {zrX: touch.x,zrY: touch.y,//需要添加的方法即可解决dataZoom报错preventDefault: () => {},stopImmediatePropagation: () => {},stopPropagation: () => {}});handler.dispatch("mousemove", {zrX: touch.x,zrY: touch.y,//需要添加的方法即可解决dataZoom报错preventDefault: () => {},stopImmediatePropagation: () => {},stopPropagation: () => {}});handler.processGesture(wrapTouch(e), "start");}}
},touchMove(e) {if (this.ec.stopTouchEvent) {e.preventDefault();e.stopPropagation();return;}this.$emit("touchmove", e);if (this.$curChart && e.touches.length > 0) {var touch = e.touches[0];var handler = this.$curChart.getZr().handler;if (handler) {handler.dispatch("mousemove", {zrX: touch.x,zrY: touch.y,//需要添加的方法即可解决dataZoom报错preventDefault: () => {},stopImmediatePropagation: () => {},stopPropagation: () => {}});handler.processGesture(wrapTouch(e), "change");}}
},touchEnd(e) {if (this.ec.stopTouchEvent) {e.preventDefault();e.stopPropagation();return;}this.$emit("touchend", e);if (this.$curChart) {const touch = e.changedTouches ? e.changedTouches[0] : {};var handler = this.$curChart.getZr().handler;if (handler) {handler.dispatch("mouseup", {zrX: touch.x,zrY: touch.y,//需要添加的方法即可解决dataZoom报错preventDefault: () => {},stopImmediatePropagation: () => {},stopPropagation: () => {}});handler.dispatch("click", {zrX: touch.x,zrY: touch.y,//需要添加的方法即可解决dataZoom报错preventDefault: () => {},stopImmediatePropagation: () => {},stopPropagation: () => {}});handler.processGesture(wrapTouch(e), "end");}}
},

这篇关于uniapp 如何使用echarts 以及解决tooltip自定义不生效;dataZoom报错问题的文章就介绍到这儿,希望我们推荐的文章对编程师们有所帮助!



http://www.chinasem.cn/article/616458

相关文章

SpringBoot项目jar依赖问题报错解析

《SpringBoot项目jar依赖问题报错解析》本文主要介绍了SpringBoot项目中常见的依赖错误类型、报错内容及解决方法,依赖冲突包括类找不到、方法找不到、类型转换异常等,本文给大家介绍的非常... 目录常见依赖错误类型及报错内容1. 依赖冲突类错误(1) ClassNotFoundExceptio

Python使用Spire.PDF实现为PDF添加水印

《Python使用Spire.PDF实现为PDF添加水印》在现代数字化办公环境中,PDF已成为一种广泛使用的文件格式,尤其是在需要保持文档格式时,下面我们就来看看如何使用Python为PDF文件添加水... 目录一、准备工作二、实现步骤1. 导入必要的库2. 创建 PdfDocument 对象3. 设置水印

python循环引用和解决过程

《python循环引用和解决过程》文章讨论了在Python中解决循环引用问题的几种方法,包括延迟导入、使用`importlib`、重构代码和类型提示的前向引用,这些方法可以帮助开发者避免导入循环导致的... 目录模拟循环引用解决python循环引用的方法有几种,以下是一些常见的解决android方案常见问题

MybatisPlus 多数据源切换@DS注解失效问题解决

《MybatisPlus多数据源切换@DS注解失效问题解决》在业务开发中使用到了多数据源,遇到了@DS注解失效问题,有两个场景使用到同一个@DS的查询方法,下面就来介绍一下该问题的解决,感兴趣的可以... 在业务开发中使用到了多数据源,遇到了@DS注解失效问题,有两个场景使用到同一个@DS的查询方法,一个正

Centos7 firewall和docker冲突问题及解决过程

《Centos7firewall和docker冲突问题及解决过程》本文描述了一个在CentOS7上使用firewalld和Docker容器的问题,当firewalld启动或重启时,会从iptable... 目录系统环境问题描述问题排查解决办法总结本文只是我对问题的记录,只能用作参考,不能China编程说明问题,请

Java中的ConcurrentBitSet使用小结

《Java中的ConcurrentBitSet使用小结》本文主要介绍了Java中的ConcurrentBitSet使用小结,文中通过示例代码介绍的非常详细,对大家的学习或者工作具有一定的参考学习价值,... 目录一、核心澄清:Java标准库无内置ConcurrentBitSet二、推荐方案:Eclipse

Go语言结构体标签(Tag)的使用小结

《Go语言结构体标签(Tag)的使用小结》结构体标签Tag是Go语言中附加在结构体字段后的元数据字符串,用于提供额外的属性信息,这些信息可以通过反射在运行时读取和解析,下面就来详细的介绍一下Tag的使... 目录什么是结构体标签?基本语法常见的标签用途1.jsON 序列化/反序列化(最常用)2.数据库操作(

Java中ScopeValue的使用小结

《Java中ScopeValue的使用小结》Java21引入的ScopedValue是一种作用域内共享不可变数据的预览API,本文就来详细介绍一下Java中ScopeValue的使用小结,感兴趣的可以... 目录一、Java ScopedValue(作用域值)详解1. 定义与背景2. 核心特性3. 使用方法

spring中Interceptor的使用小结

《spring中Interceptor的使用小结》SpringInterceptor是SpringMVC提供的一种机制,用于在请求处理的不同阶段插入自定义逻辑,通过实现HandlerIntercept... 目录一、Interceptor 的核心概念二、Interceptor 的创建与配置三、拦截器的执行顺

C#中checked关键字的使用小结

《C#中checked关键字的使用小结》本文主要介绍了C#中checked关键字的使用,文中通过示例代码介绍的非常详细,对大家的学习或者工作具有一定的参考学习价值,需要的朋友们下面随着小编来一起学习学... 目录✅ 为什么需要checked? 问题:整数溢出是“静默China编程”的(默认)checked的三种用