SupervisionDistribution.vue 3.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128
  1. <template>
  2. <div class="supervision-distribution">
  3. <div class="chart-container" ref="chart"></div>
  4. </div>
  5. </template>
  6. <script>
  7. import * as echarts from 'echarts'
  8. export default {
  9. name: 'SupervisionDistribution',
  10. props: {
  11. chartsData: {
  12. type: Array,
  13. default: () => []
  14. }
  15. },
  16. data() {
  17. return {
  18. chart: null
  19. }
  20. },
  21. mounted() {
  22. this.$nextTick(() => {
  23. this.initChart()
  24. })
  25. },
  26. watch: {
  27. chartsData: {
  28. deep: true,
  29. handler() {
  30. this.$nextTick(() => {
  31. if (this.chart) this.chart.dispose()
  32. this.initChart()
  33. })
  34. }
  35. }
  36. },
  37. methods: {
  38. initChart() {
  39. if (!this.$refs.chart) return
  40. this.chart = echarts.init(this.$refs.chart)
  41. const option = {
  42. responsive: true,
  43. maintainAspectRatio: false,
  44. grid: {
  45. left: '15%',
  46. right: '5%',
  47. bottom: '20%',
  48. top: '10%'
  49. },
  50. xAxis: {
  51. type: 'category',
  52. data: this.chartsData.map(item => item.name),
  53. axisLine: {
  54. lineStyle: {
  55. color: 'rgba(255, 255, 255, 0.1)'
  56. }
  57. },
  58. axisLabel: {
  59. color: 'rgba(255, 255, 255, 0.5)',
  60. fontSize: 9,
  61. rotate: 30
  62. }
  63. },
  64. yAxis: {
  65. type: 'value',
  66. name: '人数',
  67. nameTextStyle: {
  68. color: 'rgba(255, 255, 255, 0.5)',
  69. fontSize: 9
  70. },
  71. axisLine: { show: false },
  72. axisTick: { show: false },
  73. splitLine: {
  74. lineStyle: {
  75. color: 'rgba(255, 255, 255, 0.05)'
  76. }
  77. },
  78. axisLabel: {
  79. color: 'rgba(255, 255, 255, 0.5)',
  80. fontSize: 9
  81. }
  82. },
  83. series: [
  84. {
  85. name: '查获数量',
  86. type: 'bar',
  87. data: this.chartsData.map(item => item.num),
  88. itemStyle: {
  89. borderRadius: [5, 5, 0, 0],
  90. color: '#F462CC'
  91. },
  92. label: {
  93. show: true,
  94. position: 'top',
  95. color: '#F462CC',
  96. fontSize: 9,
  97. fontWeight: 500
  98. },
  99. barWidth: '40%'
  100. }
  101. ],
  102. tooltip: {
  103. trigger: 'axis',
  104. backgroundColor: 'rgba(13,80,122,0.95)',
  105. borderColor: '#70CFE7',
  106. textStyle: { color: '#fff' }
  107. }
  108. }
  109. this.chart.setOption(option)
  110. }
  111. },
  112. beforeDestroy() {
  113. if (this.chart) this.chart.dispose()
  114. }
  115. }
  116. </script>
  117. <style lang="scss" scoped>
  118. .supervision-distribution {
  119. .chart-container {
  120. width: 100%;
  121. height: 450rpx;
  122. }
  123. }
  124. </style>