[vue折線圖] 記錄SpringBoot+Vue3.0折線圖訂單信息展示


因公司業務需求,需要做一份訂單相關的折線圖,

 

 

如果其中有一天沒有訂單的話,這一天就是空缺的,在繪制折線圖的時候是不允許的,所有要求把沒有訂單數據的日期也要在圖表顯示。

使用技術vue3.0+springboot2.0 ,本次做一個粗略的記錄,以便后期查閱和幫助有需要的人。

效果圖:

 

 主要展示目的: 當月訂單每日的訂單數量及每日訂單總金額,如當日沒有訂單 依舊展示日期,且數量和金額均為0.

  

  先來看下主要sql:

 1 SELECT
 2     sum(money) AS totalMoney,
 3     sum(count) AS totalCount,
 4     date_format(createTime, '%m-%d') AS orderTime
 5 FROM
 6     (
 7         SELECT
 8             SUM(tos.actuallyMoney) money,
 9             count(*) count,
10             date_format(tos.createTime, '%Y-%m-%d') createTime
11         FROM
12             tb_order_shop tos
13         WHERE
14             tos.`status` = 'A'
15         AND tos.payStatus = 2
16         AND DATE_FORMAT(tos.createTime, '%Y%m') = DATE_FORMAT(CURDATE(), '%Y%m')
17         GROUP BY
18             tos.createTime
19         UNION ALL
20             SELECT
21                 @money := 0.00 AS money,
22                 @count := 0 AS count,
23                 createTime
24             FROM
25                 (
26                     SELECT
27                         @num :=@num + 1 AS number,
28                         date_format(
29                             adddate(
30                                 DATE_ADD(
31                                     curdate(),
32                                     INTERVAL - DAY (curdate()) + 1 DAY
33                                 ),
34                                 INTERVAL @num DAY
35                             ),
36                             '%Y-%m-%d'
37                         ) AS createTime
38                     FROM
39                         tb_order_shop,
40                         (SELECT @num :=- 1) t
41                     WHERE
42                         adddate(
43                             DATE_ADD(
44                                 curdate(),
45                                 INTERVAL - DAY (curdate()) + 1 DAY
46                             ),
47                             INTERVAL @num DAY
48                         ) < date_format(NOW(), '%Y-%m-%d')
49                     ORDER BY
50                         createTime
51                 ) date
52     ) shopOrder
53 GROUP BY
54     shopOrder.createTime
55 ORDER BY
56     createTime

 查詢結果:

 

 

 前端Vue代碼:

 1 <template>
 2     <div>
 3         <ve-line :data="chartData"></ve-line>
 4     </div>
 5 </template>
 6 
 7 <script>
 8     export default {
 9         data: function () {
10             return {
11                 chartData: {
12                     columns: ['日期',  '下單用戶', '總金額'],
13                     rows: []
14                 }
15             }
16         },
17         mounted() {
18             this.getOrderInfo();
19         },
20         methods:{
21             getOrderInfo(){
22                 this.$ajax({
23                     method: "post",
24                     url: "/home/getLineChartInfo"
25                 }).then(response => {
26                     let res = response.data;
27                     if (res.message == "success") {
28                         this.chartData.rows = res.data;
29                     }
30                 });
31             }
32         }
33     };
34 </script>

以上只是個人開發方法

如果您有好的方法可以在此文章下進行評論。

 


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM