aGandrass
4 months ago
350
1
Laravel

Remove quotation marks from eloquent collection - Chartjs

Posted 4 months ago by aGandrass

Hi, I am trying to implement chartjs but I am not able to parse the values to my graph view.

That's my controller: $successfullypaidbyMonth = Newpayment::where('paymentstatus', 'successfully paid') ->select(\DB::raw('SUM(total) as total_amount, MONTH(paymentdate) as month')) ->groupBy(\DB::raw('MONTH(paymentdate) DESC')) ->pluck('total_amount', 'month'); return view('maindashboard', compact('successfullypaidbyMonth');

Here I am trying to get the data: var context = document.getElementById('graph').getContext('2d'); var myChart = new Chart(context, { type: 'bar', data: { labels: {{ $successfullypaidbyMonth->keys() }}, datasets: [{ data: {{ $successfullypaidbyMonth->values() }}, backgroundColor: [ 'rgba(255, 99, 132, 0.2)', 'rgba(54, 162, 235, 0.2)', 'rgba(75, 192, 192, 0.2)' ], }] } })

Unfortunately, I do not get the values. It seems like that it is because the values have quotation marks. ^ Illuminate\Support\Collection {#1229 ▼ #items: array:2 [▼ 6 => "2600.00" 4 => "5300.00" ] }

Does anybody know what to do? Thank you very much Andre

Please sign in or create an account to participate in this conversation.