inspectionsNumChart.vue 4.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192
  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: 'inspectionsNumChart', //上报统计图表
  9. props: {
  10. chartData: {}
  11. },
  12. data() {
  13. return { myChart: null }
  14. },
  15. watch: {
  16. chartData(val) {
  17. this.$nextTick(() => {
  18. this.initialChart()
  19. })
  20. }
  21. },
  22. mounted() {
  23. //图表大小自适应
  24. window.addEventListener('resize', this.onResize)
  25. },
  26. methods: {
  27. destroyChart() {
  28. if (this.myChart != null) {
  29. this.myChart.dispose()
  30. this.myChart = null
  31. }
  32. },
  33. onResize() {
  34. if (this.myChart) {
  35. this.myChart.resize()
  36. }
  37. },
  38. initialChart() {
  39. this.destroyChart()
  40. let option = {
  41. grid: {
  42. left: '5%',
  43. right: '5%',
  44. bottom: '5%',
  45. containLabel: true
  46. },
  47. tooltip: {
  48. show: true,
  49. confine: true,
  50. borderWidth: 0,
  51. textStyle: {
  52. color: '#fff'
  53. },
  54. backgroundColor: 'rgba(50,50,50,0.7)',
  55. trigger: 'axis',
  56. axisPointer: {
  57. lineStyle: {
  58. type: 'solid',
  59. color: 'rgba(255, 255, 255, 0.3)'
  60. }
  61. }
  62. },
  63. legend: {
  64. show: true,
  65. x: 'center',
  66. y: '10',
  67. icon: 'inherit',
  68. itemHeight: 10,
  69. itemWidth: 16,
  70. textStyle: {
  71. color: '#FFFFFF'
  72. },
  73. data: ['累计次数', '每月次数']
  74. },
  75. xAxis: [
  76. {
  77. type: 'category',
  78. boundaryGap: true,
  79. axisLabel: {
  80. color: '#FFFFFF'
  81. },
  82. axisLine: {
  83. show: false
  84. },
  85. axisTick: {
  86. show: false
  87. },
  88. splitLine: {
  89. show: false
  90. },
  91. data: this.chartData.xData
  92. }
  93. ],
  94. yAxis: [
  95. {
  96. type: 'value',
  97. name: '累计次数',
  98. nameTextStyle: {
  99. color: '#FFFFFF'
  100. },
  101. axisLabel: {
  102. color: '#FFFFFF'
  103. },
  104. axisLine: {
  105. show: false
  106. },
  107. axisTick: {
  108. show: false
  109. },
  110. splitLine: {
  111. show: true,
  112. lineStyle: {
  113. color: 'rgba(255, 255, 255, 0.2)'
  114. }
  115. }
  116. },
  117. {
  118. type: 'value',
  119. name: '每月次数',
  120. position: 'right',
  121. nameTextStyle: {
  122. color: '#FFFFFF'
  123. },
  124. axisLabel: {
  125. color: '#FFFFFF'
  126. },
  127. axisLine: {
  128. show: false
  129. },
  130. axisTick: {
  131. show: false
  132. },
  133. splitLine: {
  134. show: true,
  135. lineStyle: {
  136. color: 'rgba(255, 255, 255, 0.2)'
  137. }
  138. }
  139. }
  140. ],
  141. series: [
  142. {
  143. name: '累计次数',
  144. type: 'line',
  145. symbol: 'circle',
  146. symbolSize: 8,
  147. showSymbol: false,
  148. smooth: true,
  149. itemStyle: {
  150. color: '#FFD553'
  151. },
  152. lineStyle: {
  153. color: '#FFD553',
  154. width: 2
  155. },
  156. data: this.chartData.total
  157. },
  158. {
  159. name: '每月次数',
  160. type: 'bar',
  161. barWidth: 12,
  162. itemStyle: {
  163. color: '#0EA7FF'
  164. },
  165. data: this.chartData.everydayTimes
  166. }
  167. ]
  168. }
  169. this.creatChart(option, this.$refs.chart)
  170. },
  171. creatChart(option, ref) {
  172. this.myChart = echarts.init(ref) //this.$refs.chart
  173. this.myChart.resize()
  174. this.myChart.setOption(option, {
  175. notMerge: true
  176. })
  177. }
  178. },
  179. beforeDestroy() {
  180. window.removeEventListener('resize', this.onResize)
  181. this.destroyChart()
  182. }
  183. }
  184. </script>
  185. <style lang='scss' scoped>
  186. .chart {
  187. height: 100%;
  188. width: 100%;
  189. }
  190. </style>