monitoring.vue 5.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175
  1. <template>
  2. <div class="person_box">
  3. <div ref="chartAccess" style="width: 100%;height: 100%;"></div>
  4. </div>
  5. </template>
  6. <script setup>
  7. import { ref, onMounted, watch } from 'vue';
  8. import * as echarts from 'echarts'
  9. const props = defineProps({
  10. resultData: {
  11. type: Object,
  12. default: {}
  13. }
  14. })
  15. const chartAccess = ref(null);
  16. let chartDom = null;
  17. const initAccess = (arrData, timeData) => {
  18. const color = ['#EAEA26', '#906BF9', '#FE5656', '#01E17E', '#3DD1F9', '#FFAD05']; //2个以上的series就需要用到color数组
  19. const legend = {
  20. //data,就是取得每个series里面的name属性。
  21. orient: 'horizontal',
  22. icon: 'circle', //图例形状
  23. padding: 0,
  24. top: 13,
  25. left: '4%',
  26. itemWidth: 10, //小圆点宽度
  27. itemHeight: 10, // 小圆点高度
  28. itemGap: 10, // 图例每项之间的间隔。[ default: 10 ]横向布局时为水平间隔,纵向布局时为纵向间隔。
  29. textStyle: {
  30. fontSize: 13,
  31. color: '#ffffff',
  32. },
  33. };
  34. const tooltip = {
  35. show: true,
  36. trigger: 'axis',
  37. axisPointer: {
  38. type: 'shadow',
  39. },
  40. textStyle: {
  41. color: '#fafafa',
  42. },
  43. borderColor: 'transparent',
  44. backgroundColor: 'rgba(0, 0, 0, 0.5)',
  45. extraCssText: 'backdrop-filter: blur(6px);',
  46. };
  47. let seriesData = arrData
  48. const commonConfigFn = (index) => {
  49. return {
  50. type: 'line',
  51. smooth: true,
  52. symbol: 'emptyCircle', //空心小圆点。线条小圆点形状
  53. symbolSize: 4, //小圆点大小
  54. itemStyle: {
  55. //还是小圆点设置
  56. },
  57. label: {
  58. show: false, //不显示小圆点上的label文字
  59. },
  60. lineStyle: {
  61. width: 1, //线条设置
  62. },
  63. areaStyle: {
  64. //填充线条下面的面积区域颜色。(areaStyle只是锦上添花)
  65. opacity: 0.2,
  66. color: {
  67. type: 'linear',
  68. x: 0,
  69. y: 0,
  70. x2: 0,
  71. y2: 1,
  72. colorStops: [
  73. {
  74. offset: 0,
  75. color: color[index], // 上处的颜色
  76. },
  77. {
  78. offset: 1,
  79. color: 'transparent', // 下处的颜色
  80. },
  81. ],
  82. global: false, // 缺省为 false
  83. },
  84. },
  85. };
  86. };
  87. seriesData = seriesData.map((item, index) => ({ ...item, ...commonConfigFn(index) }));
  88. if (!chartDom) {
  89. chartDom = echarts.init(chartAccess.value);
  90. }
  91. let option = {
  92. color,
  93. tooltip,
  94. legend,
  95. grid: {
  96. top: '15%',
  97. left: '4%',
  98. right: '4%',
  99. bottom: '5%',
  100. containLabel: true,
  101. },
  102. xAxis: {
  103. show: true, //显示x轴+x轴label文字
  104. type: 'category',
  105. boundaryGap: false, //从Y轴出发,这个false很好的
  106. axisLine: {
  107. show: true, //显示x坐标轴轴线
  108. lineStyle: {
  109. color: 'rgba(255,255,255,.4)',
  110. },
  111. },
  112. axisTick: {
  113. show: false, //不显示x坐标1cm刻度
  114. },
  115. axisLabel: {
  116. color: '#ffffff', //x轴label文字颜色
  117. },
  118. splitLine: {
  119. show: false, //不显示grid竖向分割线
  120. },
  121. data: timeData,
  122. },
  123. yAxis: {
  124. type: 'value',
  125. axisLabel: {
  126. color: '#ffffff',
  127. },
  128. axisLine: {
  129. show: true,
  130. lineStyle: {
  131. color: 'rgba(255,255,255,.4)',
  132. },
  133. },
  134. splitLine: {
  135. show: false, //不显示grid水平分割线
  136. },
  137. },
  138. series: seriesData,
  139. };
  140. chartDom.setOption(option)
  141. };
  142. // 生命周期
  143. onMounted(() => {
  144. let seriesData = [];
  145. let time = []
  146. initAccess(seriesData, time)
  147. });
  148. watch(() => props.resultData, (newVal) => {
  149. if (chartDom) {
  150. let time = Object.keys(newVal.Type1)
  151. let seriesData = [
  152. { name: '客流1', data: Object.entries(newVal.Type1) },
  153. { name: '客流2', data: Object.entries(newVal.Type2) },
  154. { name: '客流3', data: Object.entries(newVal.Type3) },
  155. { name: '客流4', data: Object.entries(newVal.Type4) },
  156. ];
  157. initAccess(seriesData, time)
  158. }
  159. }, { deep: true, immediate: true } // 开启深度监听
  160. )
  161. // 窗口自适应
  162. window.addEventListener('resize', () => {
  163. chartDom?.resize();
  164. });
  165. </script>
  166. <style scoped lang="scss">
  167. .person_box {
  168. width: 100%;
  169. height: 100%;
  170. display: flex;
  171. align-items: center;
  172. }
  173. </style>