lineEcharts.vue 4.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213
  1. <template>
  2. <div class="lineEchartsClass" style="padding-left: 1vw;padding-top: 1.5vh;">
  3. <div class="title">七日趋势</div>
  4. <div ref="linechart" style="width:100%;height: 90%;"></div>
  5. </div>
  6. </template>
  7. <script setup name="Index" lang="ts">
  8. import * as echarts from 'echarts';
  9. const linechart = ref();
  10. import { getpassenger } from "@/api/data"
  11. const drawEchart = (kldata,hldata) => {
  12. let echartsObj = echarts.init(linechart.value, "macarons");
  13. var dateArray = getRecentDays();
  14. var option = {
  15. legend: {
  16. top: '2%',
  17. left: 'center',
  18. textStyle: {
  19. color: '#000000'
  20. // ...
  21. }
  22. },
  23. color: ['#3a9ede', '#2ACB97'],
  24. grid: {
  25. top: "15%",
  26. left: "3%",
  27. right: "8%",
  28. bottom: "11%",
  29. containLabel: true,
  30. },
  31. xAxis: {
  32. type: "category",
  33. boundaryGap: false,
  34. data: dateArray,
  35. axisLine: {
  36. show: true,
  37. lineStyle: {
  38. color: "#353b5a",
  39. },
  40. },
  41. axisTick: {
  42. show: false,
  43. },
  44. axisLabel: {
  45. // rotate: 60,
  46. textStyle: {
  47. color: "#000000"
  48. },
  49. },
  50. },
  51. yAxis: {
  52. show: false,
  53. type: "value",
  54. nameTextStyle: {
  55. color: "#000000",
  56. padding: [0, 0, 0, -35],
  57. },
  58. name: "数量",
  59. axisLine: {
  60. show: true,
  61. lineStyle: {
  62. color: "#48A7EF",
  63. },
  64. },
  65. axisLabel: {
  66. textStyle: {
  67. color: "#fff",
  68. },
  69. },
  70. axisTick: {
  71. show: false,
  72. },
  73. splitLine: {
  74. lineStyle: {
  75. color: "#353b5a",
  76. },
  77. },
  78. },
  79. series: [
  80. {
  81. name: "客流趋势",
  82. type: "line",
  83. data: kldata,
  84. smooth: false,
  85. symbol: 'circle',
  86. itemStyle: {
  87. normal: {
  88. color: "#ffffff",
  89. borderColor: '#3a9ede',
  90. borderWidth: 1,
  91. }
  92. },
  93. lineStyle: {
  94. color: "#3a9ede",
  95. width: 2,
  96. },
  97. areaStyle: {
  98. color: {
  99. x: 0,
  100. y: 1,
  101. x2: 0,
  102. y2: 0,
  103. colorStops: [
  104. {
  105. offset: 0,
  106. color: "rgba(72, 167, 239, 0.1)", // 0% 处的颜色
  107. },
  108. {
  109. offset: 1,
  110. color: "rgba(72, 167, 239, 0.7)", // 100% 处的颜色
  111. },
  112. ],
  113. },
  114. },
  115. },
  116. {
  117. name: "货流趋势",
  118. type: "line",
  119. data: hldata,
  120. smooth: false,
  121. symbol: 'circle',
  122. itemStyle: {
  123. normal: {
  124. color: "#ffffff",
  125. borderColor: '#2ACB97',
  126. borderWidth: 1,
  127. }
  128. },
  129. lineStyle: {
  130. color: "#2ACB97",
  131. width: 2,
  132. },
  133. areaStyle: {
  134. color: {
  135. x: 0,
  136. y: 1,
  137. x2: 0,
  138. y2: 0,
  139. colorStops: [
  140. {
  141. offset: 0,
  142. color: "rgba(42, 203, 151, 0.1)", // 0% 处的颜色
  143. },
  144. {
  145. offset: 1,
  146. color: "rgba(42, 203, 151, 0.7)", // 100% 处的颜色
  147. },
  148. ],
  149. },
  150. },
  151. },
  152. ],
  153. }
  154. echartsObj.setOption(option);
  155. }
  156. const getRecentDays = () => {
  157. const oneDay = 24 * 60 * 60 * 1000; // 这里定义一天的毫秒数
  158. const resultArray = [];
  159. for (let i = 6; i >= 0; i--) {
  160. const currentDate = new Date(Date.now() - i * oneDay); // 计算出每天的日期
  161. const year = currentDate.getFullYear();
  162. const month = String(currentDate.getMonth() + 1).padStart(2, "0"); // 月份需要补零
  163. const day = String(currentDate.getDate()).padStart(2, "0"); // 日期也需要补零
  164. const formattedDate = `${month}-${day}`; // 格式化日期为 yyyy-mm-dd 的形式
  165. resultArray.push(formattedDate);
  166. }
  167. return resultArray;
  168. }
  169. const getpassengerData = () =>{
  170. getpassenger().then(res=>{
  171. console.log(res)
  172. var date = [];
  173. var kldata = [];
  174. var hldata = [];
  175. for(var index in res.data){
  176. if(index > 0){
  177. date.push(res.data[index].end);
  178. kldata.push(res.data[index].flowCount.incount + res.data[index].flowCount.outcount)
  179. hldata.push(res.data[index].goodsOrderCount.ordercount)
  180. }
  181. }
  182. drawEchart(kldata,hldata)
  183. })
  184. }
  185. onMounted(() => {
  186. getpassengerData();
  187. })
  188. </script>
  189. <style>
  190. .lineEchartsClass {
  191. height: 28vh;
  192. background: rgba(255, 255, 255, 0.85);
  193. border-radius: 8px 8px 8px 8px;
  194. box-shadow: 6px 6px 6px 6px rgba(0, 0, 0, 0.3);
  195. .title {
  196. font-family: Source Han Sans CN, Source Han Sans CN;
  197. font-weight: bold;
  198. font-size: 20px;
  199. color: #000000;
  200. line-height: 24px;
  201. text-align: left;
  202. font-style: normal;
  203. text-transform: none;
  204. }
  205. }
  206. </style>