chart.vue 4.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199
  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. },
  12. mounted() {
  13. this.$nextTick(() => {
  14. this.chart = echarts.init(this.$refs.chart, 'macarons');
  15. })
  16. },
  17. beforeDestroy() {
  18. if (!this.chart) {
  19. return
  20. }
  21. this.chart.dispose()
  22. this.chart = null
  23. },
  24. watch: {
  25. plain: {
  26. handler(value) {
  27. this.setOptions(value)
  28. },
  29. deep: true,
  30. immediate: true,
  31. }
  32. },
  33. methods: {
  34. setOptions(plain) {
  35. if (!this.chart) {
  36. return;
  37. }
  38. const { sections, wlevelmax, wlevelmin, wlevel } = plain;
  39. const seriesData = sections.map(({ x, y }) => [x, y]);
  40. const options = {
  41. xAxis: {
  42. name: '起点距',
  43. boundaryGap: false,
  44. type: 'value',
  45. min: 'dataMin',
  46. max: 'dataMax',
  47. axisLine: {
  48. lineStyle: {
  49. color: '#FF8500'
  50. }
  51. },
  52. axisTick: {
  53. lineStyle: {
  54. color: '#8D99A4'
  55. }
  56. },
  57. axisLabel: {
  58. color: '#54606C'
  59. },
  60. nameTextStyle: {
  61. color: '#54606C'
  62. }
  63. },
  64. yAxis: [
  65. {
  66. name: '高程(m)',
  67. triggerEvent: true,
  68. axisLine: {
  69. show: true,
  70. lineStyle: {
  71. color: '#FF8500'
  72. }
  73. },
  74. axisTick: {
  75. show: true,
  76. lineStyle: {
  77. color: '#8D99A4'
  78. }
  79. },
  80. axisLabel: {
  81. color: '#54606C'
  82. },
  83. nameTextStyle: {
  84. color: '#54606C'
  85. },
  86. min: 'dataMin',
  87. max: 'dataMax',
  88. },
  89. {
  90. axisLine: {
  91. show: true,
  92. lineStyle: {
  93. color: '#FF8500'
  94. }
  95. },
  96. axisTick: {
  97. show: false,
  98. },
  99. axisLabel: {
  100. show: false,
  101. },
  102. },
  103. ],
  104. grid: {
  105. left: 50,
  106. right: 50,
  107. bottom: 40,
  108. top: 40,
  109. containLabel: true
  110. },
  111. tooltip: {
  112. trigger: 'axis',
  113. axisPointer: {
  114. type: 'cross'
  115. },
  116. padding: [5, 10]
  117. },
  118. series: [{
  119. name: '高程',
  120. itemStyle: {
  121. normal: {
  122. color: '#FF8500',
  123. lineStyle: {
  124. color: '#FF8500',
  125. width: 2
  126. }
  127. }
  128. },
  129. areaStyle: {
  130. color: '#FF8500',
  131. opacity: 0.5
  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 (wlevel > wlevelmin && wlevel < wlevelmax) {
  165. options.series.push({
  166. name: '起测水位',
  167. symbol: 'none',
  168. silent: true,
  169. lineStyle: {
  170. width: 0,
  171. },
  172. data: new Array(seriesData.length).fill(wlevel),
  173. type: 'line',
  174. markLine: {
  175. symbol: 'none',
  176. silent: true,
  177. lineStyle: { normal: { type: 'dashed' } },
  178. label: { position: 'start' },
  179. data: [{
  180. name: '起测水位',
  181. yAxis: wlevel,
  182. label: {
  183. formatter: '{b}'
  184. }
  185. }],
  186. },
  187. });
  188. }
  189. this.chart.setOption(options);
  190. }
  191. }
  192. }
  193. </script>
  194. <style scoped>
  195. </style>