大家好,我正在使用 ChartJs 和 Laravel 在圖表上繪制數據,我需要根據月份繪制數據,我希望即使沒有數據也能在圖表上顯示整個 12 個月,我有幾個月的數組 ['January', 'February'....然后我在這里有我的數據: $stats = DB::table('wallet_payouts') ->groupBy('date') ->orderBy('date', 'ASC') ->get([ DB::raw('DATE_FORMAT(created_at, "%M") as date'), DB::raw('COUNT(*) as value') ]); $labels = []; $data = []; foreach ($months as $month){ foreach ($stats as $stat){ if ($month == $stat->date){ array_push($labels, $stat->date); array_push($data, $stat->value); }else{ array_push($labels, $month); array_push($data, 0); } } }但問題不是循環后 12 個月,我得到 24...重復,數據也在 24...我希望月份與沒有重復的數據匹配
排序數組和比較數組值php
幕布斯6054654
2023-03-04 10:58:46