ChartStarkBar.vue 3.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169
  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. let start = time.length - 8;
  46. let end = time.length - 1;
  47. var option = {
  48. legend: {
  49. data: ["1号楼", "2号楼", "3号楼"],
  50. },
  51. color: ["#73C0DE", "#9A60B4", "#5470C6", "#91CB74"],
  52. tooltip: {
  53. trigger: "axis",
  54. },
  55. dataZoom: [
  56. {
  57. type: "inside",
  58. startValue: start,
  59. endValue: end,
  60. show: false,
  61. },
  62. ],
  63. xAxis: [
  64. {
  65. type: "category",
  66. data: time,
  67. axisPointer: {
  68. type: "shadow",
  69. },
  70. axisLine: {
  71. show: false,
  72. lineStyle: {
  73. color: "#6e7079",
  74. },
  75. },
  76. axisTick: {
  77. show: false,
  78. },
  79. },
  80. ],
  81. yAxis: [
  82. {
  83. type: "value",
  84. name: "用料统计情况",
  85. axisLabel: {
  86. formatter: "{value} 吨",
  87. },
  88. axisLine: {
  89. show: false,
  90. lineStyle: {
  91. color: "#6e7079",
  92. },
  93. },
  94. axisTick: {
  95. show: false,
  96. },
  97. },
  98. ],
  99. series: [
  100. {
  101. name: "1号楼",
  102. data: data1,
  103. type: "bar",
  104. itemStyle: {
  105. color: this.color,
  106. borderColor: this.color,
  107. normal: {
  108. label: {
  109. show: true,
  110. position: "top",
  111. textStyle: {
  112. fontSize: 14,
  113. },
  114. },
  115. },
  116. },
  117. },
  118. {
  119. name: "2号楼",
  120. data: data2,
  121. type: "bar",
  122. itemStyle: {
  123. color: this.color,
  124. borderColor: this.color,
  125. normal: {
  126. label: {
  127. show: true,
  128. position: "top",
  129. textStyle: {
  130. fontSize: 14,
  131. },
  132. },
  133. },
  134. },
  135. },
  136. {
  137. name: "3号楼",
  138. data: data3,
  139. type: "bar",
  140. itemStyle: {
  141. color: this.color,
  142. borderColor: this.color,
  143. normal: {
  144. label: {
  145. show: true,
  146. position: "top",
  147. textStyle: {
  148. fontSize: 14,
  149. },
  150. },
  151. },
  152. },
  153. },
  154. ],
  155. };
  156. this.myChart.setOption(option);
  157. },
  158. },
  159. mounted() {
  160. this.myChart = this.$echarts.init(
  161. document.getElementById("chart-stark-bar-" + this.id)
  162. );
  163. this.init();
  164. },
  165. };
  166. </script>
  167. <style scoped></style>