plantCountChart.vue 3.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145
  1. <template>
  2. <div id="plantCountChart" :style="{height:height,width:width}"/>
  3. </template>
  4. <script>
  5. import resize from "@/views/dashboard/mixins/resize";
  6. export default {
  7. mixins: [resize],
  8. props: {
  9. statistics: {
  10. type: Array,
  11. default() {
  12. return [];
  13. }
  14. },
  15. width: {
  16. type: String,
  17. default: '100%'
  18. },
  19. height: {
  20. type: String,
  21. default: '490px'
  22. },
  23. },
  24. data() {
  25. return {
  26. chart: null,
  27. option: {
  28. title: {
  29. text: '按装置统计',
  30. textStyle: {color: '#666', fontSize: 14, fontWeight: 'normal'},
  31. padding: [5, 5, 5, 5],
  32. },
  33. legend: {
  34. orient: 'horizontal',
  35. top: 0,
  36. itemWidth: 30,
  37. itemHeight: 12,
  38. data: ['严重泄漏', '一般泄露', '未泄露']
  39. },
  40. grid: {left: 10, top: 50, bottom: 20, right: 20, containLabel: true},
  41. xAxis: {
  42. type: 'value',
  43. axisLine: {show: true, lineStyle: {color: '#ccc'}},
  44. axisLabel: {color: '#999'},
  45. splitLine: {lineStyle: {color: ['#CEEDFF'], type: [5, 8], dashOffset: 3}},
  46. },
  47. yAxis: {
  48. type: 'category',
  49. data: [],
  50. axisLine: {lineStyle: {color: '#ccc'}},
  51. axisTick: {length: 3},
  52. axisLabel: {color: '#999'},
  53. },
  54. tooltip: {
  55. trigger: 'axis',
  56. axisPointer: {type: 'shadow'},
  57. textStyle: {color: '#424242'},
  58. renderMode: 'html',
  59. className: 'tooltip',
  60. order: 'seriesDesc',
  61. },
  62. toolbox: {
  63. show: true,
  64. feature: {
  65. mark: {show: true},
  66. restore: {show: true},
  67. saveAsImage: {show: true}
  68. }
  69. },
  70. series: [
  71. {
  72. name: '严重泄漏',
  73. type: 'bar',
  74. stack: 'total', // ! 多条数据总计 => 堆叠
  75. barWidth: 30,
  76. color: '#f5804d',
  77. itemStyle: {borderRadius: [5, 5, 5, 5]},
  78. data: [],
  79. },
  80. {
  81. name: '一般泄露',
  82. type: 'bar',
  83. stack: 'total', // ! 多条数据总计 => 堆叠
  84. barWidth: 30,
  85. color: '#FFC53D',
  86. itemStyle: {borderRadius: [5, 5, 5, 5]},
  87. data: [],
  88. },
  89. {
  90. name: '未泄露',
  91. type: 'bar',
  92. stack: 'total', // ! 多条数据总计 => 堆叠
  93. barWidth: 30,
  94. color: '#8bd46e',
  95. itemStyle: {borderRadius: [5, 5, 5, 5]},
  96. data: [],
  97. },
  98. ],
  99. }
  100. }
  101. },
  102. mounted() {
  103. this.$nextTick(() => {
  104. this.initChart();
  105. })
  106. },
  107. watch: {
  108. statistics: {
  109. deep: true,
  110. immediate: true, // 监听到后,立即执行 handler方法
  111. handler: function (newVal, oldVal) {
  112. this.statisticsList = newVal
  113. this.option.series[0].data=[];
  114. this.option.series[1].data=[];
  115. this.option.series[2].data=[];
  116. this.option.yAxis.data=[];
  117. this.statisticsList.forEach(item => {
  118. if (item.plantName != '合计') {
  119. this.option.series[0].data.push(item.yzxlCount);
  120. this.option.series[1].data.push(item.ybxlCount);
  121. this.option.series[2].data.push(item.wxlCount);
  122. this.option.yAxis.data.push(item.plantName);
  123. }
  124. })
  125. this.initChart();
  126. },
  127. }
  128. },
  129. methods: {
  130. initChart() {
  131. // 基于准备好的dom,初始化echarts实例
  132. this.chart = this.echarts.init(document.getElementById('plantCountChart'))
  133. this.chart.setOption(this.option)
  134. }
  135. }
  136. }
  137. </script>
  138. <style scoped>
  139. </style>