chart-list.vue 5.0 KB

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