echartLine.vue 4.1 KB

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