 |
|
พอดีผมกำหน้า Dashboard มีกราฟ มีข้อมูล Count จำนวน ต่างๆ
มีการ Loop เพื่อ Count จำนวนในแต่ละประเภท
Code (PHP)
$chart_budget = collect([]);
$chart_budget_year = collect([]);
$year=date('Y')+543;
$year10 =$year-10;
//dd($year10);
for ($i= 1; $i <= 6; $i++) {
$chart_budget->push(Car::where('car_budgets_id',$i)->count());
$chart_budget_year->push(Car::where('car_budgets_id',$i)
->where('car_year','<=',$year10)->count());
}
$chartBudget = new SampleChart;
$chartBudget->labels(['เงินประเภท 1', 'เงินประเภท 2', 'เงินประเภท 3', 'เงินประเภท 4','เงินประเภท 5','เงินอื่นๆ ']);
$chartBudget->dataset('ข้อมูลทั้งหมด', 'bar', $chart_budget)
->backgroundColor('#81B71A');
$chartBudget->dataset('ข้อมูล 10 ปีย้อนหลัง', 'bar', $chart_budget_year)
->backgroundColor('#36a2eb');
ข้อมูลประมาณ 5 หมื่น Record กว่าจะปมวลผลเสร็จช้ามากเลยครับ
จึงอยากจะมาแลกเปลี่ยนว่า ถ้าทำ Dashboard ใช้วิธีไหนกัน
ที่มันจะ Count ไว้แล้ว เราดึงตัวเลขมาเลย หรือใช้วิธีการไหนครับ
ขอบคุณครับ
Tag : PHP, HTML5, Laravel Framework
|
|
 |
 |
 |
 |
Date :
2018-12-17 10:04:18 |
By :
the_cop |
View :
1604 |
Reply :
3 |
|
 |
 |
 |
 |
|
|
|
 |