echartLine2.vue 7.0 KB

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