chart-list.vue 5.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257
  1. <template>
  2. <div ref="chart" class="chart" :style="{height: '400px', width: '100%'}" />
  3. </template>
  4. <script>
  5. import * as echarts from "echarts";
  6. import resize from '@/utils/resize'
  7. export default {
  8. mixins: [resize],
  9. props: {
  10. plain: Object,
  11. onlyShowCurrentPlain: {
  12. type: Boolean,
  13. default: false,
  14. }
  15. },
  16. mounted() {
  17. this.$nextTick(() => {
  18. this.chart = echarts.init(this.$refs.chart, 'macarons');
  19. })
  20. },
  21. beforeDestroy() {
  22. if (!this.chart) {
  23. return
  24. }
  25. this.chart.dispose()
  26. this.chart = null
  27. },
  28. watch: {
  29. plain: {
  30. handler(value) {
  31. this.setOptions(value)
  32. },
  33. deep: true,
  34. immediate: true,
  35. }
  36. },
  37. methods: {
  38. setOptions(plain) {
  39. if (!this.chart) {
  40. return;
  41. }
  42. const { sections, wlevelmax, wlevelmin, list, waterlevel } = plain;
  43. const xAxisData = sections.map(({ x }) => x);
  44. const seriesData = sections.map(({ x, y }) => ([x, y]));
  45. const options = {
  46. xAxis: {
  47. name: '起点距',
  48. boundaryGap: false,
  49. type: 'value',
  50. min: 'dataMin',
  51. max: 'dataMax',
  52. axisLine: {
  53. lineStyle: {
  54. color: '#FF8500'
  55. }
  56. },
  57. axisTick: {
  58. lineStyle: {
  59. color: '#8D99A4'
  60. }
  61. },
  62. axisLabel: {
  63. color: '#54606C'
  64. },
  65. nameTextStyle: {
  66. color: '#54606C'
  67. }
  68. },
  69. yAxis: [
  70. {
  71. name: '高程(m)',
  72. triggerEvent: true,
  73. axisLine: {
  74. show: true,
  75. lineStyle: {
  76. color: '#FF8500'
  77. }
  78. },
  79. axisTick: {
  80. show: true,
  81. lineStyle: {
  82. color: '#8D99A4'
  83. }
  84. },
  85. axisLabel: {
  86. color: '#54606C'
  87. },
  88. nameTextStyle: {
  89. color: '#54606C'
  90. },
  91. min: 'dataMin',
  92. max: 'dataMax',
  93. },
  94. {
  95. axisLine: {
  96. show: true,
  97. lineStyle: {
  98. color: '#FF8500'
  99. }
  100. },
  101. axisTick: {
  102. show: false,
  103. },
  104. axisLabel: {
  105. show: false,
  106. },
  107. },
  108. ],
  109. grid: {
  110. left: 50,
  111. right: 50,
  112. bottom: 40,
  113. top: 40,
  114. containLabel: true
  115. },
  116. tooltip: {
  117. trigger: 'axis',
  118. axisPointer: {
  119. type: 'cross'
  120. },
  121. padding: [5, 10]
  122. },
  123. series: [{
  124. name: '高程',
  125. lineStyle: {
  126. width: 1,
  127. color: '#FF8500',
  128. },
  129. areaStyle: {
  130. opacity: 1,
  131. color: '#ffc27f',
  132. },
  133. smooth: false,
  134. symbol: 'none',
  135. type: 'line',
  136. data: seriesData,
  137. animations: false,
  138. markLine: {
  139. symbol: 'none',
  140. silent: true,
  141. lineStyle: { normal: { type: 'dashed' } },
  142. label: { position: 'start' },
  143. data: [
  144. {
  145. yAxis: wlevelmax,
  146. lineStyle: { width: 1, color: 'red' },
  147. name: '最高水位',
  148. label: {
  149. formatter: '{b}'
  150. }
  151. },
  152. {
  153. yAxis: wlevelmin,
  154. lineStyle: { width: 1, color: 'red' },
  155. name: '最低水位',
  156. label: {
  157. formatter: '{b}'
  158. }
  159. },
  160. ]
  161. },
  162. }]
  163. };
  164. if (waterlevel) {
  165. options.series.push({
  166. data: [[Math.min(...xAxisData), waterlevel],[Math.max(...xAxisData), waterlevel]],
  167. type: 'line',
  168. symbol: 'none',
  169. z: 0,
  170. lineStyle: {
  171. width: 0,
  172. },
  173. areaStyle: {
  174. opacity: 1,
  175. color: '#a5cdf7',
  176. }
  177. })
  178. }
  179. let hasSetCurrent = false;
  180. list.forEach((plain, index) => {
  181. const themes = [
  182. '#2ec7c9',
  183. '#b6a2de',
  184. '#5ab1ef',
  185. '#d87a80',
  186. '#8d98b3',
  187. '#97b552',
  188. '#95706d',
  189. '#dc69aa',
  190. '#07a2a4',
  191. '#9a7fd1',
  192. ]
  193. const { wlevel, positions, planid } = plain;
  194. if (this.onlyShowCurrentPlain && (hasSetCurrent || wlevel > waterlevel)) {
  195. return;
  196. } else {
  197. hasSetCurrent = true;
  198. }
  199. const positions1 = JSON.parse(positions) || [];
  200. const pointsData = positions1.reduce((init, p) => {
  201. const xIndex = xAxisData.findIndex(x => x === p.x);
  202. if (xIndex !== -1) {
  203. init.push({ coord: [p.x, wlevel] })
  204. }
  205. return init;
  206. }, []);
  207. options.series.push({
  208. name: `策略编号(${planid})`,
  209. symbol: 'none',
  210. itemStyle: {
  211. normal: {
  212. color: themes[index],
  213. lineStyle: {
  214. width: 0
  215. }
  216. }
  217. },
  218. data: xAxisData.map((x) => [x, wlevel]),
  219. type: 'line',
  220. markLine: {
  221. symbol: 'none',
  222. silent: true,
  223. lineStyle: {
  224. color: themes[index],
  225. },
  226. label: { position: 'start' },
  227. data: [{
  228. yAxis: wlevel,
  229. name: `策略编号(${planid})`,
  230. label: {
  231. formatter: '{b}'
  232. }
  233. }],
  234. },
  235. markPoint: {
  236. label: {
  237. formatter: ({ data }) => data.coord[0],
  238. },
  239. itemStyle: {
  240. color: themes[index],
  241. },
  242. data: pointsData,
  243. },
  244. });
  245. })
  246. this.chart.clear();
  247. this.chart.setOption(options);
  248. }
  249. }
  250. }
  251. </script>
  252. <style scoped>
  253. </style>