designAndConsChart.vue 5.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220
  1. <template>
  2. <div class="chart" ref="chart"></div>
  3. </template>
  4. <script>
  5. import * as echarts from 'echarts'
  6. import { fontSize } from '@/views/groupPage/util'
  7. export default {
  8. name: 'designAndConsChart', //设计施工综合图表
  9. props: {
  10. chartData: {
  11. default: () => {
  12. return {
  13. legendData: ['监理', '施工'],
  14. xData: ['1月', '2月', '3月', '4月', '5月', '6月', '7月', '8月', '9月', '10月', '11月', '12月'],
  15. spvData: [120, 132, 101, 134, 90, 230, 210, 182, 191, 234, 290, 330],
  16. consData: [220, 182, 191, 234, 290, 330, 310, 201, 154, 190, 330, 410]
  17. }
  18. }
  19. }
  20. },
  21. data() {
  22. return { myChart: null }
  23. },
  24. watch: {
  25. chartData(val) {
  26. this.$nextTick(() => {
  27. this.initialChart()
  28. })
  29. }
  30. },
  31. mounted() {
  32. this.$nextTick(() => {
  33. this.initialChart()
  34. })
  35. //图表大小自适应
  36. window.addEventListener('resize', this.onResize)
  37. },
  38. methods: {
  39. destroyChart() {
  40. if (this.myChart != null) {
  41. this.myChart.dispose()
  42. this.myChart = null
  43. }
  44. },
  45. onResize() {
  46. if (this.myChart) {
  47. this.myChart.resize()
  48. }
  49. },
  50. initialChart() {
  51. this.destroyChart()
  52. let legendData = this.chartData.legendData
  53. let xData = this.chartData.xData
  54. let spvData = this.chartData.spvData
  55. let consData = this.chartData.consData
  56. let option = {
  57. grid: {
  58. left: '5%',
  59. right: '5%',
  60. top: '20%',
  61. bottom: '5%',
  62. containLabel: true
  63. },
  64. tooltip: {
  65. show: true,
  66. confine: true,
  67. borderWidth: 0,
  68. textStyle: {
  69. color: '#fff'
  70. },
  71. backgroundColor: 'rgba(50,50,50,0.7)',
  72. trigger: 'axis',
  73. axisPointer: {
  74. lineStyle: {
  75. type: 'solid',
  76. color: 'rgba(255, 255, 255, 0.3)'
  77. }
  78. }
  79. },
  80. legend: {
  81. show: true,
  82. x: 'right',
  83. y: '10',
  84. icon: 'inherit',
  85. itemWidth: 15,
  86. itemHeight: 10,
  87. textStyle: {
  88. color: '#FFFFFF'
  89. },
  90. data: legendData
  91. },
  92. xAxis: [
  93. {
  94. type: 'category',
  95. boundaryGap: true,
  96. axisLabel: {
  97. color: '#FFFFFF',
  98. interval: 0
  99. },
  100. axisLine: {
  101. show: false
  102. },
  103. axisTick: {
  104. show: false
  105. },
  106. splitLine: {
  107. show: false
  108. },
  109. data: xData
  110. }
  111. ],
  112. yAxis: [
  113. {
  114. type: 'value',
  115. name: '单位:次',
  116. nameTextStyle: {
  117. color: '#FFFFFF'
  118. },
  119. axisLabel: {
  120. color: '#FFFFFF'
  121. },
  122. axisLine: {
  123. show: false
  124. },
  125. axisTick: {
  126. show: false
  127. },
  128. splitLine: {
  129. show: true,
  130. lineStyle: {
  131. color: 'rgba(255, 255, 255, 0.2)'
  132. }
  133. }
  134. }
  135. ],
  136. series: [
  137. {
  138. name: '监理',
  139. type: 'line',
  140. stack: '总量',
  141. symbol: 'circle',
  142. symbolSize: 6,
  143. showSymbol: false,
  144. smooth: true,
  145. itemStyle: {
  146. color: '#FFD553'
  147. },
  148. lineStyle: {
  149. color: '#FFD553',
  150. width: 1
  151. },
  152. areaStyle: {
  153. color: new echarts.graphic.LinearGradient(0, 1, 0, 0, [
  154. {
  155. offset: 0,
  156. color: 'rgba(7,44,90,0.3)'
  157. },
  158. {
  159. offset: 1,
  160. color: 'rgba(255, 213, 83, 1)'
  161. }
  162. ])
  163. },
  164. data: spvData
  165. },
  166. {
  167. name: '施工',
  168. type: 'line',
  169. stack: '总量',
  170. symbol: 'circle',
  171. symbolSize: 6,
  172. showSymbol: false,
  173. smooth: true,
  174. itemStyle: {
  175. color: '#0EA7FF'
  176. },
  177. lineStyle: {
  178. color: '#0EA7FF',
  179. width: 1
  180. },
  181. areaStyle: {
  182. color: new echarts.graphic.LinearGradient(0, 1, 0, 0, [
  183. {
  184. offset: 0,
  185. color: 'rgba(7,44,90,0.3)'
  186. },
  187. {
  188. offset: 1,
  189. color: 'rgba(14, 167, 255, 1)'
  190. }
  191. ])
  192. },
  193. data: consData
  194. }
  195. ]
  196. }
  197. this.creatChart(option, this.$refs.chart)
  198. },
  199. creatChart(option, ref) {
  200. this.myChart = echarts.init(ref) //this.$refs.chart
  201. this.myChart.resize()
  202. this.myChart.setOption(option, {
  203. notMerge: true
  204. })
  205. }
  206. },
  207. beforeDestroy() {
  208. window.removeEventListener('resize', this.onResize)
  209. this.destroyChart()
  210. }
  211. }
  212. </script>
  213. <style lang='scss' scoped>
  214. .chart {
  215. height: 100%;
  216. width: 100%;
  217. }
  218. </style>