businessEnergyChart.vue 4.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208
  1. <script>
  2. import apiOperationAnalysis from "@/api/operation/apiOperationAnalysis";
  3. export default {
  4. data() {
  5. return {
  6. chart: null,
  7. option: {
  8. legend: {
  9. data: [
  10. '用电(kWh)',
  11. '用水(m³)',
  12. '用热(kWh)',
  13. '用冷(kWh)',
  14. '光伏(kWh)',
  15. ],
  16. selected: {
  17. '用电(kWh)': true,
  18. '用水(m³)': true,
  19. '用热(kWh)': false,
  20. '用冷(kWh)': false,
  21. '光伏(kWh)': true,
  22. }
  23. },
  24. grid: {
  25. left: "1%", //默认10%
  26. right: "1%", //默认10%
  27. bottom: "20px", //默认60
  28. top: "60px",
  29. containLabel: true,
  30. //grid区域是否包含坐标轴的刻度标签
  31. },
  32. xAxis: {
  33. data: [],
  34. },
  35. yAxis: [
  36. {
  37. type: "value",
  38. nameTextStyle: {
  39. padding: [10, 0, 10, -30],
  40. },
  41. },
  42. ],
  43. dataZoom: this.$constant.ECHARTS_OPTION_DATAZOOM,
  44. tooltip: {
  45. trigger: "axis",
  46. axisPointer: {
  47. type: "shadow",
  48. },
  49. textStyle: {
  50. color: "#fff",
  51. align: "left",
  52. fontSize: 14,
  53. },
  54. axisLine: {
  55. //x坐标轴轴线
  56. show: true,
  57. lineStyle: {
  58. //x坐标轴轴线样式
  59. color: "#000", //'#ccc' | 'rgb(128, 128, 128)' | 'rgba(128, 128, 128, 0.5)',设置标签颜色
  60. },
  61. },
  62. backgroundColor: "rgba(0,0,0,0.8)",
  63. },
  64. series: [
  65. {
  66. name: "用电(kWh)",
  67. data: [],
  68. type: "line",
  69. stack: "a",
  70. yAxisIndex: 0,
  71. smooth: true,
  72. showSymbol: false,
  73. lineStyle: {
  74. color: "#62CC97",
  75. width: 1,
  76. },
  77. itemStyle: {
  78. color: "#62CC97",
  79. },
  80. emphasis: {
  81. scale: 1.5,
  82. },
  83. },
  84. {
  85. name: "用水(m³)",
  86. data: [],
  87. type: "line",
  88. stack: "a",
  89. yAxisIndex: 0,
  90. smooth: true,
  91. showSymbol: false,
  92. itemStyle: {
  93. color: "#3AA7E6",
  94. },
  95. lineStyle: {
  96. color: "#3AA7E6",
  97. width: 1,
  98. },
  99. emphasis: {
  100. scale: 1.5,
  101. },
  102. },
  103. {
  104. name: "用热(kWh)",
  105. data: [],
  106. type: "line",
  107. stack: "a",
  108. yAxisIndex: 0,
  109. smooth: true,
  110. showSymbol: false,
  111. itemStyle: {
  112. color: "#4ACFB8",
  113. },
  114. lineStyle: {
  115. color: "#4ACFB8",
  116. width: 1,
  117. },
  118. emphasis: {
  119. scale: 1.5,
  120. },
  121. },
  122. {
  123. name: "用冷(kWh)",
  124. data: [],
  125. type: "line",
  126. stack: "a",
  127. yAxisIndex: 0,
  128. smooth: true,
  129. showSymbol: false,
  130. itemStyle: {
  131. color: "#F4955F",
  132. },
  133. lineStyle: {
  134. color: "#F4955F",
  135. width: 1,
  136. },
  137. emphasis: {
  138. scale: 1.5,
  139. },
  140. },
  141. {
  142. name: "光伏(kWh)",
  143. data: [],
  144. type: "line",
  145. stack: "a",
  146. yAxisIndex: 0,
  147. smooth: true,
  148. showSymbol: false,
  149. itemStyle: {
  150. color: "#F8797E",
  151. },
  152. lineStyle: {
  153. color: "#F8797E",
  154. width: 1,
  155. },
  156. emphasis: {
  157. scale: 1.5,
  158. },
  159. },
  160. ],
  161. },
  162. };
  163. },
  164. props: {
  165. height: Number,
  166. queryData: Object,
  167. },
  168. mounted() {
  169. this.$nextTick(() => {
  170. this.init();
  171. });
  172. },
  173. methods: {
  174. init() {
  175. let chart = this.$echarts.init(this.$refs.myChart);
  176. this.chart = chart;
  177. this.$util.chartsResize(this.chart);
  178. chart.setOption(this.option);
  179. this.getData();
  180. },
  181. getData() {
  182. return apiOperationAnalysis
  183. .getEnergyTrendsTotal(this.queryData)
  184. .then((res) => {
  185. let data = this.$util.dataUtil.covertDataToEcharts(res, [
  186. "power",
  187. "water",
  188. "hot",
  189. "cold",
  190. "cpv",
  191. ]);
  192. this.$util.dataUtil.refreshEchartsData(this.chart, this.option, data);
  193. });
  194. },
  195. },
  196. };
  197. </script>
  198. <template>
  199. <div
  200. style="width: 100%"
  201. :style="{ height: height + 'px' }"
  202. ref="myChart"
  203. ></div>
  204. </template>
  205. <style lang="less" scoped></style>