energyConsumption.vue 4.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173
  1. <template>
  2. <div id="app-container-energy">
  3. <div class="bg-color-black">
  4. <div class="d-flex pt-2 pl-2">
  5. <span style="color:#5cd9e8">
  6. <icon name="chart-area"></icon>
  7. </span>
  8. <div class="d-flex">
  9. <span class="fs-xl text mx-2">能耗/加工损失率</span>
  10. <div class="decoration2">
  11. <dv-decoration-2 :reverse="true" style="width:5px;height:200px;" />
  12. </div>
  13. </div>
  14. </div>
  15. <div>
  16. <div id="LossrateChart" :style="transformdata ? 'transform: scale('+transformdata+') translate(0,0) !important;width:420px; height: 160px;margin: auto;' :'width:420px; height: 160px;margin: auto;'"></div>
  17. </div>
  18. </div>
  19. </div>
  20. </template>
  21. <script>
  22. import resize from "../dashboard/mixins/resize";
  23. export default {
  24. components: {},
  25. mixins: [resize],
  26. props: ['monthData','transformdata'],
  27. data() {
  28. return {
  29. chart: null
  30. }
  31. },
  32. beforeDestroy() {
  33. if (!this.chart) {
  34. return
  35. }
  36. this.chart.dispose()
  37. this.chart = null
  38. },
  39. mounted() {
  40. this.initChart();
  41. // 每隔秒请求一次数据
  42. // 每隔秒请求一次数据
  43. setInterval(() => {
  44. this.initChart();
  45. }, 3600000)
  46. },
  47. methods: {
  48. initChart() {
  49. // 基于准备好的dom,初始化echarts实例
  50. this.chart = this.echarts.init(document.getElementById('LossrateChart'))
  51. const dateDay = [];
  52. const dateNum = [];
  53. for (let i = 0; i < this.monthData.length; i++) {
  54. dateDay[i] = this.monthData[i].dateDay
  55. dateNum[i] = this.monthData[i].lossRate
  56. }
  57. this.chart.setOption({
  58. color: ['#37A2FF'],
  59. tooltip: {
  60. trigger: 'axis',
  61. axisPointer: {
  62. type: 'cross',
  63. label: {
  64. backgroundColor: '#6a7985'
  65. }
  66. }
  67. },
  68. /* 周围边距 */
  69. grid: {
  70. left: '3%',
  71. right: '7%',
  72. bottom: '1%',
  73. top: '13%',
  74. containLabel: true
  75. },
  76. xAxis: {
  77. type: 'category',
  78. boundaryGap: false,
  79. data: dateDay,
  80. axisLabel: {
  81. textStyle: {
  82. color: '#ffffff'
  83. },
  84. }
  85. },
  86. yAxis: {
  87. type: 'value',
  88. axisLabel: {
  89. textStyle: {
  90. color: '#ffffff'
  91. },
  92. formatter: '{value}%'
  93. }
  94. },
  95. series: [
  96. {
  97. name: 'Lowest',
  98. type: 'line',
  99. data: dateNum,
  100. markPoint: {
  101. data: [{ name: '周最低', value: -2, xAxis: 1, yAxis: -1.5 }]
  102. },
  103. markLine: {
  104. data: [
  105. { type: 'average', name: 'Avg' },
  106. [
  107. {
  108. symbol: 'none',
  109. x: '90%',
  110. yAxis: 'max',
  111. },
  112. {
  113. symbol: 'circle',
  114. label: {
  115. position: 'start',
  116. formatter: 'Max'
  117. },
  118. type: 'max',
  119. name: '最高点'
  120. }
  121. ]
  122. ],
  123. label: {
  124. normal: {
  125. textStyle: {
  126. color: 'white',//标注线终点文字颜色
  127. }
  128. },
  129. },
  130. },
  131. areaStyle: {
  132. color: new this.echarts.graphic.LinearGradient(0, 0, 0, 1, [
  133. {
  134. offset: 0,
  135. color: '#37A2FF'
  136. },
  137. {
  138. offset: 1,
  139. color: 'rgba(55,162,255,0)'
  140. }
  141. ])
  142. },
  143. }
  144. ]
  145. })
  146. }
  147. }
  148. }
  149. </script>
  150. <style lang="scss">
  151. #app-container-energy {
  152. padding: 0.2rem 0.2rem 0;
  153. height: 240px;
  154. min-width: 3.75rem;
  155. border-radius: 0.0625rem;
  156. .bg-color-black {
  157. height: 90%;
  158. border-radius: 0.125rem;
  159. }
  160. .text {
  161. color: #c3cbde;
  162. }
  163. //下滑线动态
  164. .decoration2 {
  165. position: absolute;
  166. right: 0.125rem;
  167. }
  168. }
  169. </style>