echartLine3.vue 5.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224
  1. <template>
  2. <div ref="work" class="work-box"></div>
  3. </template>
  4. <script lang="ts" setup>
  5. import * as echarts from 'echarts';
  6. import { ref, nextTick, reactive, watch, defineProps } from 'vue';
  7. let props = defineProps({
  8. deviceId: {
  9. type: String,
  10. },
  11. });
  12. //获取dom元素节点
  13. let work = ref<any>();
  14. let echartDataWds = reactive({});
  15. watch(
  16. () => props.deviceId,
  17. (data) => {
  18. echartDataWds = Object.assign({}, data);
  19. getOption();
  20. },
  21. { immediate: true, deep: true }
  22. );
  23. function getOption() {
  24. nextTick(() => {
  25. const myChart = echarts.init(work.value);
  26. let option = {
  27. tooltip: {
  28. trigger: 'axis',
  29. backgroundColor: 'rgba(0, 0, 0, .6)',
  30. textStyle: {
  31. color: '#fff',
  32. fontSize: 12,
  33. },
  34. },
  35. legend: {
  36. align: 'left',
  37. right: '50%',
  38. top: '0%',
  39. type: 'plain',
  40. textStyle: {
  41. color: '#7ec7ff',
  42. fontSize: 14,
  43. },
  44. // icon:'rect',
  45. itemGap: 25,
  46. itemWidth: 18,
  47. icon: 'path://M0 2a2 2 0 0 1 2 -2h14a2 2 0 0 1 2 2v0a2 2 0 0 1 -2 2h-14a2 2 0 0 1 -2 -2z',
  48. data: [
  49. {
  50. name: echartDataWds.maxData ? echartDataWds.maxData.lengedData : '',
  51. },
  52. ],
  53. },
  54. grid: {
  55. top: '20%',
  56. left: '4%',
  57. right: '4%',
  58. bottom: '20%',
  59. // containLabel: true
  60. },
  61. xAxis: [
  62. {
  63. type: 'category',
  64. boundaryGap: false,
  65. axisLine: {
  66. //坐标轴轴线相关设置。数学上的x轴
  67. show: true,
  68. lineStyle: {
  69. color: '#244a94',
  70. },
  71. },
  72. axisLabel: {
  73. //坐标轴刻度标签的相关设置
  74. textStyle: {
  75. color: '#b3b8cc',
  76. padding: 5,
  77. fontSize: 14,
  78. },
  79. formatter: function (data) {
  80. return data;
  81. },
  82. },
  83. splitLine: {
  84. show: true,
  85. lineStyle: {
  86. color: '#0d2973',
  87. type: 'dashed',
  88. },
  89. },
  90. axisTick: {
  91. show: false,
  92. },
  93. data: echartDataWds.xData,
  94. },
  95. ],
  96. yAxis: [
  97. {
  98. name: '(℃)',
  99. nameTextStyle: {
  100. color: '#7ec7ff',
  101. fontSize: 14,
  102. padding: 0,
  103. },
  104. min: 0,
  105. max: 100,
  106. splitLine: {
  107. show: true,
  108. lineStyle: {
  109. color: '#0d2973',
  110. type: 'dashed',
  111. },
  112. },
  113. axisLine: {
  114. show: true,
  115. lineStyle: {
  116. color: '#244a94',
  117. },
  118. },
  119. axisLabel: {
  120. show: true,
  121. textStyle: {
  122. color: '#b3b8cc',
  123. padding: 5,
  124. },
  125. formatter: function (value) {
  126. if (value === 0) {
  127. return value;
  128. }
  129. return value;
  130. },
  131. },
  132. axisTick: {
  133. show: false,
  134. },
  135. },
  136. ],
  137. series: [
  138. {
  139. name: echartDataWds.maxData ? echartDataWds.maxData.lengedData : '',
  140. type: 'line',
  141. smooth: true,
  142. yAxisIndex: 0,
  143. symbolSize: 8,
  144. lineStyle: {
  145. normal: {
  146. width: 2,
  147. color: '#4653fd', // 线条颜色
  148. },
  149. borderColor: 'rgba(0,0,0,.4)',
  150. },
  151. itemStyle: {
  152. color: '#4653fd',
  153. borderColor: '#646ace',
  154. borderWidth: 0,
  155. },
  156. data: echartDataWds.maxData ? echartDataWds.maxData.data : [],
  157. },
  158. {
  159. name: echartDataWds.minData ? echartDataWds.minData.lengedData : '',
  160. type: 'line',
  161. smooth: true,
  162. yAxisIndex: 0,
  163. symbolSize: 8,
  164. lineStyle: {
  165. normal: {
  166. width: 2,
  167. color: '#46fda8', // 线条颜色
  168. },
  169. borderColor: 'rgba(0,0,0,.4)',
  170. },
  171. itemStyle: {
  172. color: '#46fda8',
  173. borderColor: '#646ace',
  174. borderWidth: 0,
  175. },
  176. data: echartDataWds.minData ? echartDataWds.minData.data : [],
  177. },
  178. {
  179. name: echartDataWds.aveaData ? echartDataWds.aveaData.lengedData : '',
  180. type: 'line',
  181. smooth: true,
  182. yAxisIndex: 0,
  183. symbolSize: 8,
  184. lineStyle: {
  185. normal: {
  186. width: 2,
  187. color: '#1eb0fc', // 线条颜色
  188. },
  189. borderColor: 'rgba(0,0,0,.4)',
  190. },
  191. itemStyle: {
  192. color: '#1eb0fc',
  193. borderColor: '#646ace',
  194. borderWidth: 0,
  195. },
  196. data: echartDataWds.aveaData ? echartDataWds.aveaData.data : [],
  197. },
  198. ],
  199. };
  200. myChart.setOption(option);
  201. window.onresize = function () {
  202. myChart.resize();
  203. };
  204. });
  205. }
  206. </script>
  207. <style scoped lang="less">
  208. .work-box {
  209. width: 100%;
  210. height: 100%;
  211. }
  212. </style>