I am trying to use Chart JS in one of my laravel applications.
I am pushing the data through the route and using json_encode($gross) to echo the gross of each order by day but I am getting the following error in my console log:
Uncaught SyntaxError: Unexpected token {
It references the the line of where I have used json_encode($gross). Anyone have any ideas why this is happening?
Here is the code coming through the controller:
public function index()
{ $wkRevenue = \App\Order::where('created_at', '>=' , \Carbon\Carbon::now()->startOfMonth())->get();
// dd($wkRevenue->pluck('created_at','gross'));
return view('admin.dashboard')
->with('created_at', $wkRevenue->pluck('created_at'))
->with('grosss', $wkRevenue->pluck('gross'));
}
Here is the code in the js file:
var data = {
type:'line',
labels:['Mon','Tues','Wed','Thurs','Fri','Sat','Sun'],
datasets:[
{
data: {!! json_encode($gross) !!},
backgroundColor:'rgba(137, 200, 85, 0.4)',
}
]
}
var graph = document.getElementById('myNewChart').getContext('2d');
var myNewChart = new Chart(graph ,{
type: "line",
data: data,
options:{
title:{
display:true,
}
}
});
via JMD