carbonEmission.vue 6.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229
  1. <template>
  2. <div class="_consume">
  3. <HeadlineTag value="车牌识别(周)"></HeadlineTag>
  4. <div class="_consume_mains">
  5. <div ref="chartRef" style="width: 100%; height: 100%;"></div>
  6. </div>
  7. </div>
  8. </template>
  9. <script setup>
  10. import { ref, onMounted, onUnmounted } from 'vue';
  11. import * as echarts from 'echarts';
  12. import HeadlineTag from '@/components/HeadlineTag';
  13. const props = defineProps({
  14. resultData: {
  15. type: Object,
  16. default: {}
  17. }
  18. })
  19. const chartRef = ref(null);
  20. let chart = null;
  21. const generateRandomData = (length, max) => {
  22. const randomData = [];
  23. for (let i = 0; i < length; i++) {
  24. randomData.push(Math.floor(Math.random() * max));
  25. }
  26. return randomData;
  27. };
  28. const handleResize = () => {
  29. if (chart) {
  30. chart.resize();
  31. }
  32. };
  33. onMounted(() => {
  34. if (chartRef.value) {
  35. chart = echarts.init(chartRef.value);
  36. // 生成一周的日期数据
  37. // const weekDays = ['周一', '周二', '周三', '周四', '周五', '周六', '周日'];
  38. const weekDays = []
  39. const option = {
  40. xAxis: {
  41. type: 'category',
  42. data: weekDays,
  43. axisLabel: {
  44. color: '#fff'
  45. },
  46. },
  47. tooltip: {
  48. trigger: 'axis',
  49. axisPointer: {
  50. type: 'cross',
  51. crossStyle: {
  52. color: '#999'
  53. }
  54. }
  55. },
  56. grid: {
  57. top: '10%',
  58. bottom: '10%',
  59. right: '0%',
  60. },
  61. yAxis: {
  62. type: 'value',
  63. axisLabel: {
  64. show: true,
  65. color: '#fff'
  66. },
  67. splitLine: {
  68. show: false,
  69. lineStyle: {
  70. color: '#44585e'
  71. }
  72. },
  73. axisTick: {
  74. show: false
  75. },
  76. },
  77. series: [
  78. // 柱状图表示车牌识别
  79. {
  80. name: '车牌识别',
  81. type: 'bar',
  82. // data: generateRandomData(7, 50),
  83. data: [],
  84. barWidth: '30%',
  85. itemStyle: {
  86. color: {
  87. type: 'linear',
  88. x: 0,
  89. y: 0,
  90. x2: 0,
  91. y2: 1,
  92. colorStops: [{
  93. offset: 0, color: '#78befe' // 0% 处的颜色
  94. }, {
  95. offset: 1, color: '#0352fb' // 100% 处的颜色
  96. }],
  97. global: false // 缺省为 false
  98. },
  99. barBorderRadius: [10, 10, 10,10]
  100. },
  101. },
  102. // 曲线表示黑名单
  103. {
  104. name: '黑名单',
  105. type: 'line',
  106. // data: generateRandomData(7, 50),
  107. data: [],
  108. lineStyle: {
  109. color: '#216b87',
  110. },
  111. showSymbol: false,
  112. smooth: true,
  113. areaStyle: {
  114. color: new echarts.graphic.LinearGradient(
  115. 0,
  116. 0,
  117. 0,
  118. 1,
  119. [{
  120. offset: 0,
  121. color: 'rgba(0, 247, 255, .6)',
  122. },
  123. {
  124. offset: 0.8,
  125. color: 'rgba(0, 247, 255, .2)',
  126. },
  127. ],
  128. false
  129. ),
  130. shadowColor: 'rgba(0, 0, 0, 0.1)',
  131. shadowBlur: 10,
  132. },
  133. }
  134. ]
  135. };
  136. chart.setOption(option);
  137. }
  138. window.addEventListener('resize', handleResize);
  139. });
  140. watch(() => props.resultData, (newVal) => {
  141. if (chart) {
  142. chart.setOption({
  143. xAxis: {
  144. data: Object.keys(newVal.LicensePlateRecognition),
  145. },
  146. series: [{
  147. name: '车牌识别',
  148. data: Object.entries(newVal.LicensePlateRecognition),
  149. }, {
  150. name: '黑名单',
  151. data: Object.entries(newVal.Blacklist),
  152. }],
  153. })
  154. }
  155. }, { deep: true, immediate: true } // 开启深度监听
  156. )
  157. onUnmounted(() => {
  158. window.removeEventListener('resize', handleResize);
  159. if (chart) {
  160. chart.dispose();
  161. }
  162. });
  163. </script>
  164. <style lang="scss">
  165. ._divider {
  166. height: 1px;
  167. border: 1px dashed #168cdb;
  168. flex: 1;
  169. margin: 0 10px;
  170. }
  171. ._consume {
  172. display: flex;
  173. flex-direction: column;
  174. &_mains {
  175. margin: 10px 30px;
  176. flex: 1;
  177. display: flex;
  178. &_item {
  179. display: flex;
  180. justify-content: space-between;
  181. align-items: center;
  182. padding: 10px;
  183. &_name {
  184. width: 30px;
  185. height: 30px;
  186. background: url("@/assets/images/content_circle_num.png");
  187. background-size: 100% 100%;
  188. background-position: center;
  189. background-repeat: no-repeat;
  190. // animation: scanning 4s linear infinite;
  191. border: 1px solid red;
  192. }
  193. &_flag {
  194. display: flex;
  195. align-items: center;
  196. gap: 3px;
  197. &_item {
  198. width: 30px;
  199. height: 30px;
  200. border: 3px dashed #168cdb;
  201. box-sizing: border-box;
  202. background: #0e6ead;
  203. color: #fff;
  204. border-radius: 50%;
  205. display: flex;
  206. align-items: center;
  207. justify-content: center;
  208. font-size: 14px;
  209. }
  210. }
  211. }
  212. &_item:hover {
  213. cursor: pointer;
  214. background-image: linear-gradient(to right, #168cdb, transparent);
  215. }
  216. }
  217. }
  218. </style>