energyConsumption.vue 4.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175
  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. window.setInterval(() => {
  43. setTimeout(() => {
  44. ///调取接口获取数据
  45. this.initChart();
  46. }, 0)
  47. }, 1000 * 10 * 6 * 60 * 6)
  48. },
  49. methods: {
  50. initChart() {
  51. // 基于准备好的dom,初始化echarts实例
  52. this.chart = this.echarts.init(document.getElementById('LossrateChart'))
  53. const dateDay = [];
  54. const dateNum = [];
  55. for (let i = 0; i < this.monthData.length; i++) {
  56. dateDay[i] = this.monthData[i].dateDay
  57. dateNum[i] = this.monthData[i].lossRate
  58. }
  59. this.chart.setOption({
  60. color: ['#37A2FF'],
  61. tooltip: {
  62. trigger: 'axis',
  63. axisPointer: {
  64. type: 'cross',
  65. label: {
  66. backgroundColor: '#6a7985'
  67. }
  68. }
  69. },
  70. /* 周围边距 */
  71. grid: {
  72. left: '3%',
  73. right: '7%',
  74. bottom: '1%',
  75. top: '13%',
  76. containLabel: true
  77. },
  78. xAxis: {
  79. type: 'category',
  80. boundaryGap: false,
  81. data: dateDay,
  82. axisLabel: {
  83. textStyle: {
  84. color: '#ffffff'
  85. },
  86. }
  87. },
  88. yAxis: {
  89. type: 'value',
  90. axisLabel: {
  91. textStyle: {
  92. color: '#ffffff'
  93. },
  94. formatter: '{value}%'
  95. }
  96. },
  97. series: [
  98. {
  99. name: 'Lowest',
  100. type: 'line',
  101. data: dateNum,
  102. markPoint: {
  103. data: [{ name: '周最低', value: -2, xAxis: 1, yAxis: -1.5 }]
  104. },
  105. markLine: {
  106. data: [
  107. { type: 'average', name: 'Avg' },
  108. [
  109. {
  110. symbol: 'none',
  111. x: '90%',
  112. yAxis: 'max',
  113. },
  114. {
  115. symbol: 'circle',
  116. label: {
  117. position: 'start',
  118. formatter: 'Max'
  119. },
  120. type: 'max',
  121. name: '最高点'
  122. }
  123. ]
  124. ],
  125. label: {
  126. normal: {
  127. textStyle: {
  128. color: 'white',//标注线终点文字颜色
  129. }
  130. },
  131. },
  132. },
  133. areaStyle: {
  134. color: new this.echarts.graphic.LinearGradient(0, 0, 0, 1, [
  135. {
  136. offset: 0,
  137. color: '#37A2FF'
  138. },
  139. {
  140. offset: 1,
  141. color: 'rgba(55,162,255,0)'
  142. }
  143. ])
  144. },
  145. }
  146. ]
  147. })
  148. }
  149. }
  150. }
  151. </script>
  152. <style lang="scss">
  153. #app-container-energy {
  154. padding: 0.2rem 0.2rem 0;
  155. height: 240px;
  156. min-width: 3.75rem;
  157. border-radius: 0.0625rem;
  158. .bg-color-black {
  159. height: 90%;
  160. border-radius: 0.125rem;
  161. }
  162. .text {
  163. color: #c3cbde;
  164. }
  165. //下滑线动态
  166. .decoration2 {
  167. position: absolute;
  168. right: 0.125rem;
  169. }
  170. }
  171. </style>