由于项目需要,我使用了echarts的北京AQI可视化图,即下图这种

他里面的visualMap属性如下

visualMap: {top: 50,right: 10,pieces: [{gt: 0,lte: 50,color: '#93CE07'},{gt: 50,lte: 100,color: '#FBDB0F'},{gt: 100,lte: 150,color: '#FC7D02'},{gt: 150,lte: 200,color: '#FD0100'},{gt: 200,lte: 300,color: '#AA069F'},{gt: 300,color: '#AC3B2A'}],outOfRange: {color: '#999'}},

其中

gt:大于  gte:大于等于

lt:小于    lte:小于等于

我的数据范围值是后台给的,有的给两个边界值,有的就只给了我一个lt:0.55也就是小于0.55的线要以某种颜色显示,但是我不管是自己写还是在echarts官网试,控制台都会给我报错Cannot read properties of undefined (reading 'coord')

解决办法:

1.首先:以div来代替官网右侧的区间以及颜色说明,把官网的用show:false给隐藏掉

<divstyle="position: absolute;width: 30%;height: 6%;top: 5px;right: 3px;display:flex"><divstyle="flex:5;color:#000;display:flex;justify-content:end;align-items:center;">{{thresholdColorText}}&nbsp;&nbsp;</div><div class="thresholdColor"></div></div>
.thresholdColor {flex: 1;border-radius: 5px;background-color: blue;
}

2.我的思路: echarts官网的这个图表的visualMap属性里面,要求起码有一个数值区间是有最大值和最小值的,如果后台只返给我们一个,当后台返给我最小值,也就是数值区间以及颜色显示为

{lt:0.55,color:'blue'
}

我们就手动创造另一个有最大值和最小值的区间,这里什么意思呢,就是后台跟我说当曲线数值小于0.55的时候显示蓝色,那我就自己搞一个区间,当曲线数值大于0.55小于0.55的100倍时,显示红色,一般echarts图表没有指定y轴刻度是多少的时候,y轴刻度是不会出现0.55的100倍的数字的,只会根据你的曲线数值来显示刻度,这个时候你把这两个对象都放进visualMap的pieces的属性中,就不会报错了

{gt:0.55,lt:55,color:'red'
}

同理,当后台只返给你一个最小值,也就是数值区间以及显示颜色为

{gt:0.55,color:'blue'
}

这里意思是当曲线数值大于0.55时显示蓝色,我们就手动创造一个区间,当曲线数值小于0.55大于负的0.55的100倍时,显示红色

{gt:-55,lt:0.55,color:'red'
}

下面的js代码主要讲的就是创建新的区间,然后去初始化echarts图的配置项,里面有的配置项可能你用不到,删了就行

         // 对只传给阈值最大值或最小值进行处理
// this.threshold是后台返给我的一个对象,里面有边界值(即lt或lte或gt或gte)和要显示的颜色(即color)let threshold1 = {};
// 当传给我的值只有一个最大值的时候if (this.threshold.lt != undefined ||this.threshold.lte != undefined) {threshold1.color = "#FF0000";threshold1.gt =this.threshold.lt != undefined? this.threshold.lt: this.threshold.lte;threshold1.lt =this.threshold.lt != undefined? parseInt((this.threshold.lt * 100).toFixed(0)): parseInt((this.threshold.lte * 100).toFixed(0));this.thresholdColorText =this.threshold.lt != undefined? "< " + this.threshold.lt: "≤ " + this.threshold.lte;} else if (this.threshold.gt != undefined ||this.threshold.gte != undefined) {threshold1.color = "#FF0000";threshold1.lt =this.threshold.gt != undefined? this.threshold.gt: this.threshold.gte;threshold1.gt =this.threshold.gt != undefined? -parseInt((this.threshold.gt * 100).toFixed(0)): -parseInt((this.threshold.gte * 100).toFixed(0));this.thresholdColorText =this.threshold.gt != undefined? "> " + this.threshold.gt: "≥ " + this.threshold.gte;}let option = {title: {text: "",left: "1%"},tooltip: {trigger: "axis"},grid: {left: "10%",right: "15%",bottom: "10%"},xAxis: {data: this.time.map(function(item) {return item;})},yAxis: {},visualMap: {show: false,type: "piecewise",// splitNumber: 2,top: 10,right: 10,precision: 0, //数据展示的小数精度,默认为0,无小数点pieces: [this.threshold, threshold1],outOfRange: {color: "#FF0000"}},series: {name: "实时曲线",type: "line",data: this.value.map(function(item) {return item;}),markLine: {silent: true,lineStyle: {color: "red"},data: this.yAxisList}}};myChart.setOption(option);window.onresize = myChart.resize;

最后效果图如下

我当时被echarts图的这个bug真的搞得很烦,实在没办法才想到这样做,我在我的项目里应用起来暂时没发现什么问题,不知道这个方法通不通用

echarts 报错Cannot read properties of undefined (reading ‘coord‘)相关推荐

  1. vue引入echarts中国地图 Cannot read properties of undefined (reading ‘echarts‘) at eval (webpack-inter

    Cannot read properties of undefined (reading 'echarts') at eval (webpack-internal:///./src/views/my_ ...

  2. 引入echarts的js文件报错——Cannot read properties of null (reading ‘getAttribute‘)

    今天在引入echarts.min.js的时候总是报错: 报错如下: 该问题为:无法读取空的属性"获取属性" 根据分析,错误原因有两个: 1.初始化echarts对象不存在 2.js ...

  3. vue 3.0 keep-alive 失效 报错 Cannot read properties of null (reading ‘parentNode‘)

    版本: vue "3.2.4" vue-loader "16.4.1" vue-router "4.0.11" <router-vie ...

  4. 【echarts报错】[Vue warn]: Error in mounted hook (Promise/async): “TypeError: Cannot read properties of

    echarts安装创建图表时报这种错误:[Vue warn]: Error in mounted hook (Promise/async): "TypeError: Cannot read ...

  5. Uncaught TypeError: Cannot read properties of undefined (reading ‘push’) ---- vue-router报错

    坑点 在使用vue-router@4的时候,由于vue3中没有this.router这个写法,所以我就将解构router方法,放在了函数中,由于函数有作用域就报了这个错误:Uncaught TypeE ...

  6. 修复报错 Error in render: “TypeError: Cannot read properties of undefined (reading ‘xxx‘)“

    请求接口时,能够完整渲染出整体界面无问题,但是一刷新所渲染的界面就没了,并且开发者工具报出"Error in render: "TypeError: Cannot read pro ...

  7. react 谷歌浏览器报错:Uncaught TypeError: Cannot read properties of undefined (reading ‘forEach‘)

    运行react项目,报错: Uncaught TypeError: Cannot read properties of undefined (reading 'forEach')at Object.i ...

  8. Vue报错:Error in v-on handler: “TypeError: Cannot read properties of undefined (reading ‘skuId‘)“

    背景: 当点击按钮时候,正常情况控制台的Network应该要发送一个变化量,现在控制台的Network不仅不显示,而且还报错,报错信息如下: vue.runtime.esm.js?c320:619 [ ...

  9. 关于原生js里报这个错:Cannot read properties of undefined (reading ‘classList‘) at HTMLLIElement.

    说是不能读取classList这个属性,我写的代码是这样的 let lis = document.querySelectorAll(".tab .tab-item");let di ...

最新文章

  1. c++ lambda函数_C++ Lambda表达式
  2. 有一种爱,永远也无法逾越
  3. Mybatis指定日志输出实现
  4. pkdownloaderror错误8如何解决_8个深度学习/计算机视觉错误,应该如何避免它们
  5. lodash源码分析之Hash缓存
  6. python简单爬虫(一)
  7. Java 获取文件目录最终的修改时间
  8. 第五课--使用定时器实现中断(1)
  9. 11.Linux 高性能服务器编程 --- 定时器
  10. Java 拦截器自定义(添加响应头)
  11. U盘数据恢复软件EasyRecovery的使用教程
  12. php写的公告栏代码,可爱的公告栏代码
  13. Linux 两个服务器之间测试传输速度,测试两台服务器之间的网络带宽
  14. spider_study 1
  15. C# async / await 任务超时处理
  16. MP4文件格式的相关内容
  17. wordpress企业网站主题仿制04-wordpress企业网站产品页面新闻页面仿制
  18. 说一下数据库有哪些索引类型,有什么优缺点?
  19. zencart忘记后台密码的解决办法
  20. modbus从机模拟软件:modbus Slave和modsim

热门文章

  1. 盛世昊通顺利登陆美国纳斯达克,产业链布局加速
  2. 人力资源管理的六大模块
  3. Linux Wireless netlink socket nl80211
  4. 西海情歌用计算机怎么弹,西海情歌-降央卓玛-和弦谱-《弹吧》官网tan8.com-和弦谱大全,学吉他,秀吉他...
  5. 基于PHP+MySQL的化妆品销售购物网站
  6. C语言不用临时变量交换a,b的值
  7. 天猫淘宝店铺数据统计与自动分析杜邦模型表
  8. linux下利用dd和iso文件制作启动盘方法
  9. VisualDiffer for mac 1.6.6 文件夹视图对比文件删除
  10. 正式迁入深圳户籍-用爱发电