transit.vue 5.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202
  1. <template>
  2. <div class="_consume_mains">
  3. <div ref="chartRef" style="width: 100%; height: 100%;"></div>
  4. </div>
  5. </template>
  6. <script setup>
  7. import { ref, onMounted, onUnmounted } from 'vue';
  8. import * as echarts from 'echarts';
  9. import HeadlineTag from '@/components/HeadlineTag';
  10. const props = defineProps({
  11. resultData: {
  12. type: Object,
  13. default: {}
  14. }
  15. })
  16. const chartRef = ref(null);
  17. let chart = null;
  18. const generateRandomData = (length, max) => {
  19. const randomData = [];
  20. for (let i = 0; i < length; i++) {
  21. randomData.push(Math.floor(Math.random() * max));
  22. }
  23. return randomData;
  24. };
  25. const handleResize = () => {
  26. if (chart) {
  27. chart.resize();
  28. }
  29. };
  30. onMounted(() => {
  31. if (chartRef.value) {
  32. chart = echarts.init(chartRef.value);
  33. // 修改为 24 小时
  34. // const hours = Array.from({ length: 24 }, (_, i) => `${i}时`);
  35. const hours = []
  36. const option = {
  37. xAxis: {
  38. type: 'category',
  39. // 使用 24 小时数据
  40. data: hours,
  41. axisLabel: {
  42. color: '#fff'
  43. },
  44. },
  45. tooltip: {
  46. trigger: 'axis',
  47. axisPointer: {
  48. type: 'cross',
  49. crossStyle: {
  50. color: '#999'
  51. }
  52. }
  53. },
  54. grid: {
  55. top: '10%',
  56. bottom: '10%',
  57. right: '0%',
  58. },
  59. yAxis: {
  60. type: 'value',
  61. axisLabel: {
  62. show: true,
  63. color: '#fff'
  64. },
  65. splitLine: {
  66. show: false,
  67. lineStyle: {
  68. color: '#44585e'
  69. }
  70. },
  71. axisTick: {
  72. show: false
  73. },
  74. },
  75. series: [
  76. {
  77. name: '24小时能耗',
  78. // data: generateRandomData(7, 50),
  79. data: [],
  80. type: 'line',
  81. showSymbol: false,
  82. smooth: true,
  83. color: '#00F7FF',
  84. lineStyle: {
  85. width: 2,
  86. },
  87. areaStyle: {
  88. color: new echarts.graphic.LinearGradient(
  89. 0,
  90. 0,
  91. 0,
  92. 1,
  93. [{
  94. offset: 0,
  95. color: 'rgba(0, 247, 255, .6)',
  96. },
  97. {
  98. offset: 0.8,
  99. color: 'rgba(0, 247, 255, .2)',
  100. },
  101. ],
  102. false
  103. ),
  104. shadowColor: 'rgba(0, 0, 0, 0.1)',
  105. shadowBlur: 10,
  106. },
  107. symbol: 'circle',
  108. symbolSize: 6,
  109. }
  110. ]
  111. };
  112. chart.setOption(option);
  113. }
  114. });
  115. watch(() => props.resultData, (newVal) => {
  116. if (chart) {
  117. chart.setOption({
  118. xAxis: {
  119. data: Object.keys(newVal.PrevailingTrends),
  120. },
  121. series: [{
  122. type: 'line',
  123. data: Object.entries(newVal.PrevailingTrends),
  124. }],
  125. })
  126. }
  127. }, { deep: true, immediate: true } // 开启深度监听
  128. )
  129. onUnmounted(() => {
  130. window.removeEventListener('resize', handleResize);
  131. if (chart) {
  132. chart.dispose();
  133. }
  134. });
  135. </script>
  136. <style lang="scss">
  137. ._divider {
  138. height: 1px;
  139. border: 1px dashed #168cdb;
  140. flex: 1;
  141. margin: 0 10px;
  142. }
  143. ._consume {
  144. display: flex;
  145. flex-direction: column;
  146. &_mains {
  147. margin: 10px 30px;
  148. flex: 1;
  149. display: flex;
  150. &_item {
  151. display: flex;
  152. justify-content: space-between;
  153. align-items: center;
  154. padding: 10px;
  155. &_name {
  156. width: 30px;
  157. height: 30px;
  158. background: url("@/assets/images/content_circle_num.png");
  159. background-size: 100% 100%;
  160. background-position: center;
  161. background-repeat: no-repeat;
  162. // animation: scanning 4s linear infinite;
  163. border: 1px solid red;
  164. }
  165. &_flag {
  166. display: flex;
  167. align-items: center;
  168. gap: 3px;
  169. &_item {
  170. width: 30px;
  171. height: 30px;
  172. border: 3px dashed #168cdb;
  173. box-sizing: border-box;
  174. background: #0e6ead;
  175. color: #fff;
  176. border-radius: 50%;
  177. display: flex;
  178. align-items: center;
  179. justify-content: center;
  180. font-size: 14px;
  181. }
  182. }
  183. }
  184. &_item:hover {
  185. cursor: pointer;
  186. background-image: linear-gradient(to right, #168cdb, transparent);
  187. }
  188. }
  189. }
  190. </style>