echartLine2.vue 6.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229
  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: '50%',
  34. top: '0%',
  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: echartDataWds.maxData ? echartDataWds.maxData.lengedData : '',
  47. },
  48. ],
  49. },
  50. grid: {
  51. top: '20%',
  52. left: '4%',
  53. right: '4%',
  54. bottom: '20%',
  55. // containLabel: true
  56. },
  57. xAxis: [
  58. {
  59. type: 'category',
  60. boundaryGap: false,
  61. axisLine: {
  62. //坐标轴轴线相关设置。数学上的x轴
  63. show: true,
  64. lineStyle: {
  65. color: '#244a94',
  66. },
  67. },
  68. axisLabel: {
  69. //坐标轴刻度标签的相关设置
  70. textStyle: {
  71. color: '#b3b8cc',
  72. padding: 5,
  73. fontSize: 14,
  74. },
  75. formatter: function (data) {
  76. return data
  77. },
  78. },
  79. splitLine: {
  80. show: true,
  81. lineStyle: {
  82. color: '#0d2973',
  83. type: 'dashed',
  84. },
  85. },
  86. axisTick: {
  87. show: false,
  88. },
  89. data: echartDataWds.xData,
  90. },
  91. ],
  92. yAxis: [
  93. {
  94. name: '(℃)',
  95. nameTextStyle: {
  96. color: '#7ec7ff',
  97. fontSize: 14,
  98. padding: 0,
  99. },
  100. min: 0,
  101. max: 2000,
  102. splitLine: {
  103. show: true,
  104. lineStyle: {
  105. color: '#0d2973',
  106. type: 'dashed',
  107. },
  108. },
  109. axisLine: {
  110. show: true,
  111. lineStyle: {
  112. color: '#244a94',
  113. },
  114. },
  115. axisLabel: {
  116. show: true,
  117. textStyle: {
  118. color: '#b3b8cc',
  119. padding: 5,
  120. },
  121. formatter: function (value) {
  122. if (value === 0) {
  123. return value
  124. }
  125. return value
  126. },
  127. },
  128. axisTick: {
  129. show: false,
  130. },
  131. },
  132. ],
  133. series: [
  134. {
  135. name: echartDataWds.maxData ? echartDataWds.maxData.lengedData : '',
  136. type: 'line',
  137. smooth: true,
  138. yAxisIndex: 0,
  139. symbolSize: 8,
  140. lineStyle: {
  141. normal: {
  142. width: 2,
  143. color: '#4653fd', // 线条颜色
  144. },
  145. borderColor: 'rgba(0,0,0,.4)',
  146. },
  147. itemStyle: {
  148. color: '#4653fd',
  149. borderColor: '#646ace',
  150. borderWidth: 0,
  151. },
  152. data: echartDataWds.maxData ? echartDataWds.maxData.data : [],
  153. },
  154. {
  155. name: echartDataWds.minData ? echartDataWds.minData.lengedData : '',
  156. type: 'line',
  157. smooth: true,
  158. yAxisIndex: 0,
  159. symbolSize: 8,
  160. lineStyle: {
  161. normal: {
  162. width: 2,
  163. color: '#46fda8', // 线条颜色
  164. },
  165. borderColor: 'rgba(0,0,0,.4)',
  166. },
  167. itemStyle: {
  168. color: '#46fda8',
  169. borderColor: '#646ace',
  170. borderWidth: 0,
  171. },
  172. data: echartDataWds.minData ? echartDataWds.minData.data : [],
  173. },
  174. {
  175. name: echartDataWds.aveaData ? echartDataWds.aveaData.lengedData : '',
  176. type: 'line',
  177. smooth: true,
  178. yAxisIndex: 0,
  179. symbolSize: 8,
  180. lineStyle: {
  181. normal: {
  182. width: 2,
  183. color: '#1eb0fc', // 线条颜色
  184. },
  185. borderColor: 'rgba(0,0,0,.4)',
  186. },
  187. itemStyle: {
  188. color: '#1eb0fc',
  189. borderColor: '#646ace',
  190. borderWidth: 0,
  191. },
  192. data: echartDataWds.aveaData ? echartDataWds.aveaData.data : [],
  193. },
  194. ],
  195. }
  196. myChart.setOption(option)
  197. window.onresize = function () {
  198. myChart.resize()
  199. }
  200. })
  201. }
  202. </script>
  203. <style scoped lang="less">
  204. .echart-work {
  205. width: 100%;
  206. height: 100%;
  207. .work-box {
  208. width: 100%;
  209. height: 100%;
  210. }
  211. }
  212. </style>