carbonEmission.vue 8.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279
  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 option = {
  39. xAxis: {
  40. type: 'category',
  41. data: weekDays,
  42. axisLabel: {
  43. color: '#fff'
  44. },
  45. },
  46. tooltip: {
  47. trigger: 'axis',
  48. axisPointer: {
  49. type: 'cross',
  50. crossStyle: {
  51. color: '#999'
  52. }
  53. },
  54. textStyle: {
  55. color: '#fafafa',
  56. },
  57. borderColor: 'transparent',
  58. backgroundColor: 'rgba(0, 0, 0, 0.5)',
  59. extraCssText: 'backdrop-filter: blur(6px);',
  60. },
  61. grid: {
  62. top: '10%',
  63. bottom: '10%',
  64. right: '0%',
  65. },
  66. yAxis: {
  67. type: 'value',
  68. axisLabel: {
  69. show: true,
  70. color: '#fff'
  71. },
  72. splitLine: {
  73. show: false,
  74. lineStyle: {
  75. color: '#44585e'
  76. }
  77. },
  78. axisTick: {
  79. show: false
  80. },
  81. },
  82. series: [
  83. // 柱状图表示运行正常
  84. {
  85. name: '卫生问题',
  86. type: 'bar',
  87. // data: generateRandomData(7, 50),
  88. data: [],
  89. barWidth: '30%',
  90. itemStyle: {
  91. color: {
  92. type: 'linear',
  93. x: 0,
  94. y: 0,
  95. x2: 0,
  96. y2: 1,
  97. colorStops: [{
  98. offset: 0, color: '#78befe' // 0% 处的颜色
  99. }, {
  100. offset: 1, color: '#0352fb' // 100% 处的颜色
  101. }],
  102. global: false // 缺省为 false
  103. },
  104. borderRadius: [10, 10, 10,10]
  105. },
  106. },
  107. // 曲线表示运行异常
  108. {
  109. name: '安全问题',
  110. type: 'line',
  111. // data: generateRandomData(7, 50),
  112. data: [],
  113. lineStyle: {
  114. color: '#3b90d7',
  115. },
  116. showSymbol: false,
  117. smooth: true,
  118. areaStyle: {
  119. color: new echarts.graphic.LinearGradient(
  120. 0,
  121. 0,
  122. 0,
  123. 1,
  124. [{
  125. offset: 0,
  126. color: 'rgba(59,144,215, .6)',
  127. },
  128. {
  129. offset: 0.8,
  130. color: 'rgba(59,144,215, .2)',
  131. },
  132. ],
  133. false
  134. ),
  135. shadowColor: 'rgba(0, 0, 0, 0.1)',
  136. shadowBlur: 10,
  137. },
  138. },
  139. {
  140. name: '设施设备问题',
  141. type: 'line',
  142. // data: generateRandomData(7, 50),
  143. data: [],
  144. lineStyle: {
  145. color: '#ffc107',
  146. },
  147. showSymbol: false,
  148. smooth: true,
  149. areaStyle: {
  150. color: new echarts.graphic.LinearGradient(
  151. 0,
  152. 0,
  153. 0,
  154. 1,
  155. [{
  156. offset: 0,
  157. color: 'rgba(255, 193, 7, .6)',
  158. },
  159. {
  160. offset: 0.8,
  161. color: 'rgba(255, 193, 7, .2)',
  162. },
  163. ],
  164. false
  165. ),
  166. shadowColor: 'rgba(0, 0, 0, 0.1)',
  167. shadowBlur: 10,
  168. },
  169. }
  170. ]
  171. };
  172. chart.setOption(option);
  173. }
  174. window.addEventListener('resize', handleResize);
  175. });
  176. watch(() => props.resultData, (newVal) => {
  177. if (chart) {
  178. let arrData = Object.keys(newVal)
  179. let arr1 = []
  180. let arr2 = []
  181. let arr3 = []
  182. arrData.forEach((item)=>{
  183. let data = Object.entries(newVal[item])
  184. arr1.push(data[0][1])
  185. arr2.push(data[1][1])
  186. arr3.push(data[2][1])
  187. })
  188. chart.setOption({
  189. xAxis: {
  190. data: Object.keys(newVal),
  191. },
  192. series: [{
  193. name: '卫生问题',
  194. data: arr1,
  195. },{
  196. name: '安全问题',
  197. data: arr2,
  198. },{
  199. name: '设施设备问题',
  200. data: arr3,
  201. }],
  202. })
  203. }
  204. }, { deep: true, immediate: true } // 开启深度监听
  205. )
  206. onUnmounted(() => {
  207. window.removeEventListener('resize', handleResize);
  208. if (chart) {
  209. chart.dispose();
  210. }
  211. });
  212. </script>
  213. <style lang="scss">
  214. ._divider {
  215. height: 1px;
  216. border: 1px dashed #168cdb;
  217. flex: 1;
  218. margin: 0 10px;
  219. }
  220. ._consume {
  221. display: flex;
  222. flex-direction: column;
  223. &_mains {
  224. margin: 10px 30px;
  225. flex: 1;
  226. display: flex;
  227. &_item {
  228. display: flex;
  229. justify-content: space-between;
  230. align-items: center;
  231. padding: 10px;
  232. &_name {
  233. width: 30px;
  234. height: 30px;
  235. background: url("@/assets/images/content_circle_num.png");
  236. background-size: 100% 100%;
  237. background-position: center;
  238. background-repeat: no-repeat;
  239. // animation: scanning 4s linear infinite;
  240. border: 1px solid red;
  241. }
  242. &_flag {
  243. display: flex;
  244. align-items: center;
  245. gap: 3px;
  246. &_item {
  247. width: 30px;
  248. height: 30px;
  249. border: 3px dashed #168cdb;
  250. box-sizing: border-box;
  251. background: #0e6ead;
  252. color: #fff;
  253. border-radius: 50%;
  254. display: flex;
  255. align-items: center;
  256. justify-content: center;
  257. font-size: 14px;
  258. }
  259. }
  260. }
  261. &_item:hover {
  262. cursor: pointer;
  263. background-image: linear-gradient(to right, #168cdb, transparent);
  264. }
  265. }
  266. }
  267. </style>