定制软件开发echarts 报错Cannot read properties of undefined (reading ‘coord‘)

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

 他里面的visualMap属性如下

  1. visualMap: {
  2. top: 50,
  3. right: 10,
  4. pieces: [
  5. {
  6. gt: 0,
  7. lte: 50,
  8. color: '#93CE07'
  9. },
  10. {
  11. gt: 50,
  12. lte: 100,
  13. color: '#FBDB0F'
  14. },
  15. {
  16. gt: 100,
  17. lte: 150,
  18. color: '#FC7D02'
  19. },
  20. {
  21. gt: 150,
  22. lte: 200,
  23. color: '#FD0100'
  24. },
  25. {
  26. gt: 200,
  27. lte: 300,
  28. color: '#AA069F'
  29. },
  30. {
  31. gt: 300,
  32. color: '#AC3B2A'
  33. }
  34. ],
  35. outOfRange: {
  36. color: '#999'
  37. }
  38. },

其中

gt:大于  gte:大于等于

lt:小于    :小于等于

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

解决办法:

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

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

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

  1. {
  2. lt:0.55,
  3. color:'blue'
  4. }

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

  1. {
  2. gt:0.55,
  3. lt:55,
  4. color:'red'
  5. }

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

  1. {
  2. gt:0.55,
  3. color:'blue'
  4. }

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

  1. {
  2. gt:-55,
  3. lt:0.55,
  4. color:'red'
  5. }

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

  1. // 对只传给阈值最大值或最小值进行处理
  2. // this.threshold是后台返给我的一个对象,里面有边界值(即lt或lte或gt或gte)和要显示的颜色(即color)
  3. let threshold1 = {};
  4. // 当传给我的值只有一个最大值的时候
  5. if (
  6. this.threshold.lt != undefined ||
  7. this.threshold.lte != undefined
  8. ) {
  9. threshold1.color = "#FF0000";
  10. threshold1.gt =
  11. this.threshold.lt != undefined
  12. ? this.threshold.lt
  13. : this.threshold.lte;
  14. threshold1.lt =
  15. this.threshold.lt != undefined
  16. ? parseInt((this.threshold.lt * 100).toFixed(0))
  17. : parseInt((this.threshold.lte * 100).toFixed(0));
  18. this.thresholdColorText =
  19. this.threshold.lt != undefined
  20. ? "< " + this.threshold.lt
  21. : "≤ " + this.threshold.lte;
  22. } else if (
  23. this.threshold.gt != undefined ||
  24. this.threshold.gte != undefined
  25. ) {
  26. threshold1.color = "#FF0000";
  27. threshold1.lt =
  28. this.threshold.gt != undefined
  29. ? this.threshold.gt
  30. : this.threshold.gte;
  31. threshold1.gt =
  32. this.threshold.gt != undefined
  33. ? -parseInt((this.threshold.gt * 100).toFixed(0))
  34. : -parseInt((this.threshold.gte * 100).toFixed(0));
  35. this.thresholdColorText =
  36. this.threshold.gt != undefined
  37. ? "> " + this.threshold.gt
  38. : "≥ " + this.threshold.gte;
  39. }
  40. let option = {
  41. title: {
  42. text: "",
  43. left: "1%"
  44. },
  45. tooltip: {
  46. trigger: "axis"
  47. },
  48. grid: {
  49. left: "10%",
  50. right: "15%",
  51. bottom: "10%"
  52. },
  53. xAxis: {
  54. data: this.time.map(function(item) {
  55. return item;
  56. })
  57. },
  58. yAxis: {},
  59. visualMap: {
  60. show: false,
  61. type: "piecewise",
  62. // splitNumber: 2,
  63. top: 10,
  64. right: 10,
  65. precision: 0, //数据展示的小数精度,默认为0,无小数点
  66. pieces: [this.threshold, threshold1],
  67. outOfRange: {
  68. color: "#FF0000"
  69. }
  70. },
  71. series: {
  72. name: "实时曲线",
  73. type: "line",
  74. data: this.value.map(function(item) {
  75. return item;
  76. }),
  77. markLine: {
  78. silent: true,
  79. lineStyle: {
  80. color: "red"
  81. },
  82. data: this.yAxisList
  83. }
  84. }
  85. };
  86. myChart.setOption(option);
  87. window.onresize = myChart.resize;

最后效果图如下

 

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

网站建设定制开发 软件系统开发定制 定制软件开发 软件开发定制 定制app开发 app开发定制 app开发定制公司 电商商城定制开发 定制小程序开发 定制开发小程序 客户管理系统开发定制 定制网站 定制开发 crm开发定制 开发公司 小程序开发定制 定制软件 收款定制开发 企业网站定制开发 定制化开发 android系统定制开发 定制小程序开发费用 定制设计 专注app软件定制开发 软件开发定制定制 知名网站建设定制 软件定制开发供应商 应用系统定制开发 软件系统定制开发 企业管理系统定制开发 系统定制开发