I am using Laravel 5.7 and ConsoleTVs/charts version 5.* bar chart to show the total expenses month-wise of the current year. Here is my code what I have tried.
$expenses = Expense::selectRaw("SUM(amount) as total_amount, MONTH(date) as month")->whereYear('date', date('Y'))->groupBy('month')->get();
Query Output:
Collection {#273 ▼
#items: array:1 [▼
0 => Expense {#275 ▼
#attributes: array:2 [▼
"total_amount" => "4014"
"month" => 1
]
]
}
$chart = Charts::database($expenses, 'bar', 'highcharts')
->title("Monthly Expenses")
->elementLabel("Total Expenses")
->dimensions(1000, 600)
->responsive(false)
->groupByMonth(date('Y'), true);
return view('chart',compact('chart'));
I have tried this but got the empty bar chart. I have also tried to get only total_amount from the query result before the $chart variable like,
$expenses_total = $expenses->map(function(Expense $expense){
return $expense->total_amount;
});
But yet I didn't got the expected result.
I want the total expenses of the months of current year.
from Newest questions tagged laravel-5 - Stack Overflow http://bit.ly/2CTgUuQ
via IFTTT
Aucun commentaire:
Enregistrer un commentaire