echartLine.vue 4.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183
  1. <template>
  2. <div class="echartLine">
  3. <div class="line" ref="line"></div>
  4. </div>
  5. </template>
  6. <script lang="ts" setup>
  7. import {defineProps, ref, nextTick, reactive, watch, } from 'vue';
  8. import * as echarts from 'echarts';
  9. let props = defineProps({
  10. echartDataGq: {
  11. type: Object,
  12. },
  13. maxY:{
  14. type:Number
  15. }
  16. });
  17. //获取dom元素节点
  18. let line = ref<any>();
  19. let echartDataGqs=reactive({})
  20. watch(
  21. () => props.echartDataGq,
  22. (data) => {
  23. echartDataGqs=Object.assign({},data)
  24. getOption();
  25. },
  26. { immediate: true,deep:true }
  27. );
  28. function getOption() {
  29. nextTick(() => {
  30. const myChart = echarts.init(line.value);
  31. let option = {
  32. grid: {
  33. top: '6%',
  34. left: '2%',
  35. bottom: '6%',
  36. right: '2%',
  37. containLabel: true,
  38. },
  39. tooltip: {
  40. trigger: 'axis',
  41. },
  42. xAxis: [
  43. {
  44. type: 'category',
  45. boundaryGap: false,
  46. axisLabel: {
  47. formatter: '{value}',
  48. fontSize: 14,
  49. margin: 20,
  50. textStyle: {
  51. color: '#b3b8cc',
  52. },
  53. },
  54. axisLine: {
  55. lineStyle: {
  56. color: 'rgba(14, 53, 95)',
  57. },
  58. },
  59. splitLine: {
  60. show: false,
  61. // lineStyle: {
  62. // color: '#243753',
  63. // },
  64. },
  65. axisTick: {
  66. show: false,
  67. },
  68. data: echartDataGqs.xData ? echartDataGqs.xData : [],
  69. },
  70. ],
  71. yAxis: [
  72. {
  73. boundaryGap: false,
  74. type: 'value',
  75. max: props.maxY,
  76. axisLabel: {
  77. textStyle: {
  78. color: '#b3b8cc',
  79. },
  80. },
  81. nameTextStyle: {
  82. color: '#fff',
  83. fontSize: 12,
  84. lineHeight: 40,
  85. },
  86. splitLine: {
  87. lineStyle: {
  88. color: 'rgba(14, 53, 95)',
  89. },
  90. },
  91. axisLine: {
  92. show: true,
  93. lineStyle: {
  94. color: 'rgba(14, 53, 95)',
  95. },
  96. },
  97. axisTick: {
  98. show: false,
  99. },
  100. },
  101. ],
  102. series: [
  103. {
  104. name:echartDataGqs.maxData ? echartDataGqs.maxData.lengedData : '',
  105. type: 'line',
  106. smooth: true,
  107. showSymbol: true,
  108. symbolSize: 8,
  109. zlevel: 3,
  110. itemStyle: {
  111. color: '#19a3df',
  112. borderColor: '#a3c8d8',
  113. },
  114. lineStyle: {
  115. normal: {
  116. width: 2,
  117. color: '#19a3df',
  118. },
  119. },
  120. data:echartDataGqs.maxData ? echartDataGqs.maxData.data : [],
  121. },
  122. {
  123. name:echartDataGqs.minData ? echartDataGqs.minData.lengedData : '' ,
  124. type: 'line',
  125. smooth: true,
  126. showSymbol: true,
  127. symbolSize: 8,
  128. zlevel: 3,
  129. itemStyle: {
  130. color: '#4fffad',
  131. borderColor: '#a3c8d8',
  132. },
  133. lineStyle: {
  134. normal: {
  135. width: 2,
  136. color: '#4fffad',
  137. },
  138. },
  139. data:echartDataGqs.minData ? echartDataGqs.minData.data : [],
  140. },
  141. {
  142. name: echartDataGqs.aveValue ? echartDataGqs.aveValue.lengedData : '',
  143. type: 'line',
  144. smooth: true,
  145. showSymbol: true,
  146. symbolSize: 8,
  147. zlevel: 3,
  148. itemStyle: {
  149. color: '#fc8452',
  150. borderColor: '#a3c8d8',
  151. },
  152. lineStyle: {
  153. normal: {
  154. width: 2,
  155. color: '#fc8452',
  156. },
  157. },
  158. data:echartDataGqs.aveValue ? echartDataGqs.aveValue.data : [],
  159. },
  160. ],
  161. };
  162. myChart.setOption(option);
  163. window.onresize = function () {
  164. myChart.resize();
  165. };
  166. });
  167. }
  168. </script>
  169. <style scoped lang="less">
  170. .echartLine {
  171. width: 100%;
  172. height: 100%;
  173. .line {
  174. width: 100%;
  175. height: 100%;
  176. }
  177. }
  178. </style>