flightStatisticsCharts.vue 6.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256
  1. <template>
  2. <div class="statstics-wrapper">
  3. <div
  4. ref="headerWrapper"
  5. class="statstics-header"
  6. >
  7. <FlightStatisticsHeader title="航班量统计" />
  8. </div>
  9. <div class="statstics-content">
  10. <div
  11. id="chart"
  12. class="flight-statistics-chart"
  13. :style="{ height: chartHeight }"
  14. />
  15. </div>
  16. </div>
  17. </template>
  18. <script>
  19. import FlightStatisticsHeader from '../components/flightStatisticsHeader.vue'
  20. import { mapGetters } from 'vuex'
  21. export default {
  22. name: 'FlightStatisticsCharts',
  23. components: { FlightStatisticsHeader },
  24. data() {
  25. return {
  26. myChart: null,
  27. debounceTime: 300,
  28. chartHeight: '70vh',
  29. options: {
  30. backgroundColor: '#fff',
  31. tooltip: {
  32. trigger: 'axis',
  33. axisPointer: {
  34. type: 'cross',
  35. crossStyle: {
  36. color: '#999'
  37. }
  38. }
  39. },
  40. legend: {
  41. top: '5%',
  42. right: '5%',
  43. data: ['航班量数量', '航班量同比', '航班量环比'],
  44. textStyle: {
  45. fontFamily: 'Helvetica, "Microsoft YaHei"',
  46. color: '#101116'
  47. }
  48. },
  49. grid: {
  50. top: '10%',
  51. left: '5%',
  52. right: '5%',
  53. bottom: '5%'
  54. },
  55. xAxis: {
  56. data: [
  57. '2020.01',
  58. '2020.02',
  59. '2020.03',
  60. '2020.04',
  61. '2020.05',
  62. '2020.06',
  63. '2020.07',
  64. '2020.08',
  65. '2020.09',
  66. '2020.10',
  67. '2020.11',
  68. '2020.12',
  69. '2021.01',
  70. '2021.02',
  71. '2021.03',
  72. '2021.04'
  73. ],
  74. axisLine: {
  75. show: true,
  76. lineStyle: {
  77. color: '#000000'
  78. }
  79. },
  80. axisTick: {
  81. show: false // 隐藏X轴刻度
  82. },
  83. axisLabel: {
  84. fontFamily: 'Helvetica, "Microsoft YaHei"',
  85. color: '#101116'
  86. },
  87. axisPointer: {
  88. type: 'shadow'
  89. }
  90. },
  91. yAxis: [
  92. {
  93. min: 0,
  94. max: 60000,
  95. interval: 5000,
  96. splitLine: {
  97. lineStyle: {
  98. type: 'dashed',
  99. color: '#B0B3C3',
  100. opacity: 0.5
  101. }
  102. },
  103. axisPointer: {
  104. label: {
  105. formatter: ({ value }) => value.toFixed()
  106. }
  107. },
  108. axisLabel: {
  109. fontFamily: 'Helvetica, "Microsoft YaHei"',
  110. color: '#101116'
  111. }
  112. },
  113. {
  114. min: -0.3,
  115. max: 0.5,
  116. interval: 0.1,
  117. axisLabel: {
  118. formatter: value => (value * 100).toFixed(2) + '%',
  119. fontFamily: 'Helvetica, "Microsoft YaHei"',
  120. color: '#101116'
  121. },
  122. axisPointer: {
  123. label: {
  124. formatter: ({ value }) => (value * 100).toFixed(2) + '%'
  125. }
  126. },
  127. splitLine: {
  128. show: false
  129. }
  130. }
  131. ],
  132. series: [
  133. {
  134. name: '航班量数量',
  135. type: 'bar',
  136. z: 2,
  137. itemStyle: {
  138. color: '#6682B5'
  139. },
  140. barWidth: 40,
  141. data: [
  142. 54000, 54000, 54000, 54000, 54000, 54000, 54000, 54000, 54000, 54000, 54000, 54000, 54000, 54000, 54000,
  143. 54000
  144. ]
  145. },
  146. {
  147. name: '航班量同比',
  148. type: 'line',
  149. z: 4,
  150. yAxisIndex: 1,
  151. symbol: 'circle',
  152. itemStyle: {
  153. color: '#F2B849',
  154. borderColor: '#ffffff',
  155. borderWidth: 4
  156. },
  157. lineStyle: {
  158. width: 4,
  159. color: '#F2B849'
  160. },
  161. symbolSize: 32,
  162. tooltip: {
  163. valueFormatter: value => (value * 100).toFixed(2) + '%'
  164. },
  165. data: [0.3, 0.3, 0.3, 0.3, 0.3, 0.3, 0.3, 0.3, 0.3, 0.3, 0.3, 0.3, 0.3, 0.3, 0.3, 0.3]
  166. },
  167. {
  168. name: '航班量环比',
  169. type: 'line',
  170. z: 3,
  171. yAxisIndex: 1,
  172. symbol: 'circle',
  173. itemStyle: {
  174. color: '#E33D3D',
  175. borderColor: '#ffffff',
  176. borderWidth: 4
  177. },
  178. lineStyle: {
  179. width: 4,
  180. color: '#E33D3D'
  181. },
  182. symbolSize: 32,
  183. tooltip: {
  184. valueFormatter: value => (value * 100).toFixed(2) + '%'
  185. },
  186. data: [0.2, 0.2, 0.2, 0.2, 0.2, 0.2, 0.2, 0.2, 0.2, 0.2, 0.2, 0.2, 0.2, 0.2, 0.2, 0.2]
  187. }
  188. ]
  189. }
  190. }
  191. },
  192. computed: {
  193. ...mapGetters(['sidebar'])
  194. },
  195. watch: {
  196. // 监听数据变化 重绘图形
  197. options: {
  198. handler(obj) {
  199. this.myChart.setOption(obj)
  200. },
  201. deep: true
  202. },
  203. 'sidebar.expand'() {
  204. this.resizeHandler()
  205. }
  206. },
  207. mounted() {
  208. this.setChartHeight()
  209. this.myChart = this.$echarts.init(document.getElementById('chart'))
  210. this.myChart.setOption(this.options)
  211. // 监听页面缩放
  212. window.addEventListener('resize', this.setChartHeight)
  213. window.addEventListener('resize', this._.debounce(this.resizeHandler, this.debounceTime))
  214. this.$nextTick(() => {
  215. this.resizeHandler()
  216. })
  217. },
  218. beforeDestroy() {
  219. // 销毁实例和移除监听
  220. window.removeEventListener('resize', this.setChartHeight)
  221. if (this.myChart) {
  222. this.myChart.dispose()
  223. window.removeEventListener('resize', this.resizeHandler)
  224. this.myChart = null
  225. }
  226. },
  227. methods: {
  228. setChartHeight() {
  229. const topBarHeight = 80
  230. const headerHeight = this.$refs['headerWrapper'].offsetHeight
  231. const footerBlackHeight = 24
  232. this.chartHeight = `calc(100vh - ${topBarHeight + headerHeight + footerBlackHeight}px)`
  233. },
  234. resizeHandler() {
  235. if (this.myChart) {
  236. this.myChart.resize()
  237. }
  238. }
  239. }
  240. }
  241. </script>
  242. <style lang="scss" scoped>
  243. .statstics-wrapper {
  244. padding-left: 24px;
  245. padding-right: 36px;
  246. .statstics-header {
  247. padding-top: 16px;
  248. }
  249. .flight-statistics-chart {
  250. width: 100%;
  251. }
  252. }
  253. </style>