scenicDetailTrend.vue 4.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217
  1. <template>
  2. <div class="content">
  3. <!-- 标题区域 -->
  4. <div class="header">游客近8小时趋势走势</div>
  5. <!-- 内容区域 -->
  6. <div class="box" ref="lineChart"></div>
  7. </div>
  8. </template>
  9. <script setup lang="ts">
  10. import { onMounted, ref, nextTick } from "vue";
  11. import * as Echarts from "echarts";
  12. // 引入景区相关的接口
  13. import { reqGetHourByYesterday, reqGetHourByToday } from "@/api/scenic/index";
  14. // 折线图DOM元素
  15. const lineChart = ref(null);
  16. // 昨日数据
  17. const yesterdayData = ref([]);
  18. // 今日数据
  19. const todayData = ref([]);
  20. // x轴时间数据
  21. const timeData = ref([]);
  22. onMounted(() => {
  23. // 获取游客人数今日12小时趋势
  24. getHourByToday();
  25. // 获取游客人数昨日12小时趋势
  26. getHourByYesterday();
  27. });
  28. // 获取游客人数今日12小时趋势
  29. const getHourByToday = async () => {
  30. const res = await reqGetHourByToday();
  31. // console.log(res);
  32. todayData.value = res.data.map((ele: any) => ele.num * 1);
  33. };
  34. // 获取游客人数昨日12小时趋势
  35. const getHourByYesterday = async () => {
  36. const res = await reqGetHourByYesterday();
  37. // console.log(res);
  38. timeData.value = res.data.map((ele: any) => ele.dateTime.slice(-2) + ":00");
  39. yesterdayData.value = res.data.map((ele: any) => ele.num * 1);
  40. nextTick(() => {
  41. // 初始化折线图
  42. initLineChart();
  43. });
  44. };
  45. // 初始化折线图
  46. const initLineChart = () => {
  47. let myLineChart = Echarts.init(lineChart.value);
  48. // 折线图配置
  49. const options = {
  50. tooltip: {
  51. trigger: "axis",
  52. axisPointer: {
  53. type: "line",
  54. lineStyle: {
  55. color: "#fff",
  56. type: "solid",
  57. },
  58. },
  59. },
  60. legend: {
  61. top: 40,
  62. right: 20,
  63. icon: "roundRect",
  64. data: ["今日", "昨日"],
  65. textStyle: {
  66. color: "#fff",
  67. },
  68. },
  69. grid: {
  70. left: "0%",
  71. right: "10%",
  72. top: "25%",
  73. bottom: "5%",
  74. containLabel: true,
  75. },
  76. xAxis: {
  77. type: "category",
  78. name: "小时",
  79. nameTextStyle: {
  80. color: "#fff",
  81. fontSize: 14,
  82. },
  83. boundaryGap: true,
  84. axisTick: {
  85. show: false,
  86. },
  87. axisLabel: {
  88. color: "#7AADFF",
  89. fontSize: 14,
  90. },
  91. data: timeData.value.slice(0, 8).reverse(),
  92. },
  93. yAxis: {
  94. type: "value",
  95. name: "人数",
  96. nameTextStyle: {
  97. color: "#fff",
  98. fontSize: 14,
  99. },
  100. // min: 30,
  101. // max: 100,
  102. axisLabel: {
  103. color: "#fff",
  104. fontSize: 14,
  105. },
  106. splitLine: {
  107. show: true,
  108. lineStyle: {
  109. color: ["rgba(32, 121, 160, 0.5)"],
  110. },
  111. },
  112. },
  113. series: [
  114. {
  115. name: "今日",
  116. type: "line",
  117. smooth: true,
  118. symbol: "none",
  119. itemStyle: {
  120. color: "#F2B949",
  121. },
  122. tooltip: {
  123. valueFormatter: function (value: any) {
  124. return value + "人";
  125. },
  126. },
  127. areaStyle: {
  128. color: {
  129. type: "linear",
  130. x: 0,
  131. y: 1,
  132. x2: 0,
  133. y2: 0,
  134. colorStops: [
  135. {
  136. offset: 0,
  137. color: "rgba(242,185,73, 0.2)",
  138. },
  139. {
  140. offset: 1,
  141. color: "rgba(154, 161, 255, 0.6)",
  142. },
  143. ],
  144. },
  145. },
  146. data: todayData.value.slice(0, 8),
  147. },
  148. {
  149. name: "昨日",
  150. type: "line",
  151. smooth: true,
  152. symbol: "none",
  153. itemStyle: {
  154. color: "#0368FF",
  155. },
  156. tooltip: {
  157. valueFormatter: function (value: any) {
  158. return value + "人";
  159. },
  160. },
  161. areaStyle: {
  162. color: {
  163. type: "linear",
  164. x: 0,
  165. y: 1,
  166. x2: 0,
  167. y2: 0,
  168. colorStops: [
  169. {
  170. offset: 0,
  171. color: "#2B63CE",
  172. },
  173. {
  174. offset: 1,
  175. color: "#2B63CE",
  176. },
  177. ],
  178. },
  179. },
  180. data: yesterdayData.value.slice(0, 8),
  181. },
  182. ],
  183. };
  184. myLineChart.setOption(options);
  185. };
  186. </script>
  187. <style lang="scss" scoped>
  188. .content {
  189. width: 484px;
  190. height: 490px;
  191. .header {
  192. padding-left: 44px;
  193. width: 484px;
  194. height: 48px;
  195. font-size: 28px;
  196. font-family: "庞门正道标题体";
  197. background-image: url(@/assets/images/scenicDetail-title-img2.png);
  198. background-size: 100% 100%;
  199. }
  200. .box {
  201. width: 484px;
  202. height: 442px;
  203. }
  204. }
  205. </style>