ChartStarkBar.vue 3.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155
  1. <template>
  2. <div :id="'chart-stark-bar-'+ id" style="width: 100%; height: 100%"></div>
  3. </template>
  4. <script>
  5. export default {
  6. name: "ChartStarkBar",
  7. props: {
  8. id: {
  9. type: String,
  10. default: () => '0'
  11. },
  12. starkList: {
  13. type: Array,
  14. default: () => []
  15. }
  16. },
  17. watch: {
  18. starkList: {
  19. handler(newVal) {
  20. if(newVal) {
  21. this.myChart.clear();
  22. this.init()
  23. }
  24. },
  25. deep: true
  26. }
  27. },
  28. data() {
  29. return {
  30. myChart: null
  31. }
  32. },
  33. methods: {
  34. init() {
  35. var time = [];
  36. var data1 = [];
  37. var data2 = [];
  38. var data3 = []
  39. this.starkList.forEach(item => {
  40. time.push(item.screateTime);
  41. data1.push(item.onevalue)
  42. data2.push(item.twovalue)
  43. data3.push(item.threevalue)
  44. })
  45. var option = {
  46. legend: {
  47. data: ['1号楼', '2号楼', '3号楼']
  48. },
  49. tooltip: {
  50. trigger: 'axis',
  51. },
  52. xAxis: [
  53. {
  54. type: 'category',
  55. data: time,
  56. axisPointer: {
  57. type: 'shadow'
  58. },
  59. axisLine: {
  60. show: false,
  61. lineStyle: {
  62. color: '#6e7079',
  63. }
  64. },
  65. axisTick:{
  66. show:false
  67. },
  68. }
  69. ],
  70. yAxis: [
  71. {
  72. type: 'value',
  73. name: '用料统计情况',
  74. axisLabel: {
  75. formatter: '{value} 吨'
  76. },
  77. axisLine: {
  78. show: false,
  79. lineStyle: {
  80. color: '#6e7079',
  81. }
  82. },
  83. axisTick:{
  84. show:false
  85. },
  86. }
  87. ],
  88. series: [
  89. {
  90. name: '1号楼',
  91. data: data1,
  92. type: 'bar',
  93. itemStyle : {
  94. color: this.color,
  95. borderColor: this.color,
  96. normal: {
  97. label : {
  98. show: true,
  99. textStyle: {
  100. fontSize: 14
  101. }
  102. }
  103. }
  104. },
  105. },
  106. {
  107. name: '2号楼',
  108. data: data2,
  109. type: 'bar',
  110. itemStyle : {
  111. color: this.color,
  112. borderColor: this.color,
  113. normal: {
  114. label : {
  115. show: true,
  116. textStyle: {
  117. fontSize: 14
  118. }
  119. }
  120. }
  121. },
  122. },
  123. {
  124. name: '3号楼',
  125. data: data3,
  126. type: 'bar',
  127. itemStyle : {
  128. color: this.color,
  129. borderColor: this.color,
  130. normal: {
  131. label : {
  132. show: true,
  133. textStyle: {
  134. fontSize: 14
  135. }
  136. }
  137. }
  138. },
  139. }
  140. ]
  141. };
  142. this.myChart.setOption(option)
  143. }
  144. },
  145. mounted() {
  146. this.myChart = this.$echarts.init(document.getElementById('chart-stark-bar-' + this.id));
  147. this.init()
  148. }
  149. }
  150. </script>
  151. <style scoped>
  152. </style>