AreaDistribution.vue 2.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132
  1. <template>
  2. <div class="area-distribution">
  3. <div class="chart-container" ref="areaChart"></div>
  4. </div>
  5. </template>
  6. <script>
  7. import * as echarts from 'echarts'
  8. export default {
  9. name: 'AreaDistribution',
  10. props: {
  11. chartsData: {
  12. type: Object,
  13. default: () => ({
  14. labels: ['T1-A区', 'T1-B区', 'T2-A区', 'T2-B区', 'T3-A区', 'T3-B区'],
  15. data: [320, 280, 350, 380, 320, 332]
  16. })
  17. }
  18. },
  19. data() {
  20. return {
  21. chart: null
  22. }
  23. },
  24. mounted() {
  25. this.$nextTick(() => {
  26. this.initChart()
  27. })
  28. },
  29. watch: {
  30. chartsData: {
  31. deep: true,
  32. handler() {
  33. this.$nextTick(() => {
  34. if (this.chart) this.chart.dispose()
  35. this.initChart()
  36. })
  37. }
  38. }
  39. },
  40. methods: {
  41. initChart() {
  42. if (!this.$refs.areaChart) return
  43. this.chart = echarts.init(this.$refs.areaChart)
  44. const option = {
  45. responsive: true,
  46. maintainAspectRatio: false,
  47. tooltip: {
  48. trigger: 'axis',
  49. axisPointer: { type: 'shadow' }
  50. },
  51. legend: {
  52. data: ['查获数量'],
  53. textStyle: { color: '#666', fontSize: 10 },
  54. top: 0
  55. },
  56. grid: {
  57. left: '15%',
  58. right: '5%',
  59. bottom: '15%',
  60. top: '22%'
  61. },
  62. xAxis: {
  63. type: 'category',
  64. data: this.chartsData.labels,
  65. axisLine: {
  66. lineStyle: {
  67. color: 'rgba(0, 0, 0, 0.1)'
  68. }
  69. },
  70. axisLabel: {
  71. color: '#666',
  72. fontSize: 10,
  73. // rotate: 30
  74. }
  75. },
  76. yAxis: {
  77. type: 'value',
  78. axisLine: {
  79. show: false
  80. },
  81. axisTick: {
  82. show: false
  83. },
  84. splitLine: {
  85. lineStyle: {
  86. color: 'rgba(0, 0, 0, 0.05)'
  87. }
  88. },
  89. axisLabel: {
  90. color: '#666',
  91. fontSize: 10
  92. }
  93. },
  94. series: [{
  95. type: 'bar',
  96. data: this.chartsData.data,
  97. itemStyle: {
  98. color: {
  99. type: 'linear',
  100. x: 0,
  101. y: 0,
  102. x2: 0,
  103. y2: 1,
  104. colorStops: [{
  105. offset: 0, color: '#A78BFA'
  106. }, {
  107. offset: 1, color: '#6366F1'
  108. }]
  109. }
  110. },
  111. barWidth: '60%'
  112. }]
  113. }
  114. this.chart.setOption(option)
  115. }
  116. },
  117. beforeDestroy() {
  118. if (this.chart) this.chart.dispose()
  119. }
  120. }
  121. </script>
  122. <style lang="scss" scoped>
  123. .area-distribution {
  124. .chart-container {
  125. height: 280rpx;
  126. }
  127. }
  128. </style>