chartTemp.vue 4.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177
  1. <template>
  2. <div id="chart-temp" style="width: 100%; height: 450px"></div>
  3. </template>
  4. <script>
  5. export default {
  6. name: "chartTemp",
  7. data() {
  8. return {
  9. myCharts: null
  10. }
  11. },
  12. props: {
  13. tempList: {
  14. type: Array
  15. }
  16. },
  17. watch: {
  18. tempList: {
  19. handler(newVal) {
  20. if(newVal) {
  21. this.myCharts.clear();
  22. this.init();
  23. }
  24. },
  25. deep: true,
  26. }
  27. },
  28. methods: {
  29. init() {
  30. let options;
  31. let that = this;
  32. if(this.tempList[0].length > 0) {
  33. options = {
  34. legend: {
  35. data: ['耳根温度', '环境温度'],
  36. x: 'center',
  37. y: '5%',
  38. },
  39. tooltip: {
  40. trigger: 'axis',
  41. // formatter: '{b} <br/>{a0}: {c0}℃',
  42. // position(pt) {
  43. // return [pt[0], '10%'];
  44. // },
  45. },
  46. dataZoom: [{
  47. type: 'inside',
  48. start: 90,
  49. end: 100,
  50. }, {
  51. start: 0,
  52. end: 10,
  53. handleIcon: 'M10.7,11.9v-1.3H9.3v1.3c-4.9,0.3-8.8,4.4-8.8,9.4c0,5,3.9,9.1,8.8,9.4v1.3h1.3v-1.3c4.9-0.3,8.8-4.4,8.8-9.4C19.5,16.3,15.6,12.2,10.7,11.9z M13.3,24.4H6.7V23h6.6V24.4z M13.3,19.6H6.7v-1.4h6.6V19.6z',
  54. handleSize: '80%',
  55. handleStyle: {
  56. color: '#fff',
  57. shadowBlur: 3,
  58. shadowColor: 'rgba(0, 0, 0, 0.6)',
  59. shadowOffsetX: 2,
  60. shadowOffsetY: 2,
  61. },
  62. }],
  63. grid: {
  64. left: '2%',
  65. right: '4%',
  66. bottom: '12%',
  67. containLabel: true,
  68. },
  69. xAxis: {
  70. type: 'category',
  71. boundaryGap: false,
  72. data: that.tempList[0],
  73. },
  74. yAxis: {
  75. type: 'value',
  76. name: '单位:℃',
  77. boundaryGap: [0, '100%'],
  78. min(value) {
  79. return value.min - 1;
  80. },
  81. axisLabel: {
  82. formatter(value) {
  83. return value.toFixed(2);
  84. },
  85. },
  86. },
  87. series: [
  88. {
  89. name: '耳根温度',
  90. type: 'line',
  91. smooth: true,
  92. // symbol: 'none',
  93. sampling: 'average',
  94. itemStyle: {
  95. normal: {
  96. color: '#7ED3F4', // 改变折线点的颜色
  97. // label: { // 显示数值
  98. // show: true
  99. // }
  100. },
  101. },
  102. data: that.tempList[1],
  103. },
  104. {
  105. name: '环境温度',
  106. type: 'line',
  107. smooth: true,
  108. sampling: 'average',
  109. itemStyle: {
  110. normal: {
  111. color: '#7387F3', // 改变折线点的颜色
  112. // label: { // 显示数值
  113. // show: true
  114. // }
  115. },
  116. },
  117. data: that.tempList[2],
  118. },
  119. ],
  120. }
  121. } else {
  122. options = {
  123. title: {
  124. text: '暂无数据',
  125. x: 'center',
  126. y: 'center',
  127. textStyle: {
  128. color: '#000000',
  129. fontWeight: 'normal',
  130. fontSize: 12,
  131. },
  132. },
  133. grid: {
  134. left: '3%',
  135. right: '4%',
  136. bottom: '3%',
  137. containLabel: true,
  138. },
  139. xAxis: {
  140. type: 'category',
  141. boundaryGap: false,
  142. data: [],
  143. axisLabel: {
  144. show: true,
  145. textStyle: {
  146. color: '#000000', // 更改坐标轴文字颜色
  147. },
  148. },
  149. },
  150. yAxis: {
  151. type: 'value',
  152. axisLabel: {
  153. show: true,
  154. textStyle: {
  155. color: '#000000', // 更改坐标轴文字颜色
  156. },
  157. },
  158. },
  159. }
  160. }
  161. this.myCharts.setOption(options);
  162. }
  163. },
  164. mounted() {
  165. this.myCharts = this.$echarts.init(document.getElementById('chart-temp'));
  166. this.init();
  167. window.onresize = () => {
  168. this.myCharts.resize();
  169. }
  170. }
  171. }
  172. </script>
  173. <style scoped>
  174. </style>