大家好,我正在使用 ChartJs 和 Laravel 在圖表上繪制數(shù)據(jù),我需要根據(jù)月份繪制數(shù)據(jù),我希望即使沒有數(shù)據(jù)也能在圖表上顯示整個(gè) 12 個(gè)月,我有幾個(gè)月的數(shù)組 ['January', 'February'....然后我在這里有我的數(shù)據(jù): $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); } } }但問題不是循環(huán)后 12 個(gè)月,我得到 24...重復(fù),數(shù)據(jù)也在 24...我希望月份與沒有重復(fù)的數(shù)據(jù)匹配
排序數(shù)組和比較數(shù)組值php
幕布斯6054654
2023-03-04 10:58:46