Just wanna share. I use Laravel 5.5. So in my Controller:
$data = Mymodel::select(‘id’,’tablecolumn1′, ‘tablecolumn2’)->orderBy(‘tablecolumn2’)->get();
Using $data->toArray(); the result need to be converted to requirement of Canvas JS, so I just use the syntax str_replace as necessary ():
$data = str_replace(‘”tablecolumn2″‘, ‘x’, $data);
$data = str_replace(‘”tablecolumn1″‘, ‘y’, $data);
$data = str_replace(‘”id”‘, ‘label’, $data);
$data = str_replace(‘label:’, ‘label:”‘, $data);
$data = str_replace(‘,y:’, ‘”,y:’, $data);
Then pass the variable to the view :
return view(‘pages.charts.canvasjs2’, [ ‘data’ => $data ]);
Dont forget to delete $data->toArray(), it gives me error if not deleted.
Then in view, in dataPoints, I just put the following :
dataPoints: <?php echo $data; ?>
And in the tooltip:
toolTipContent: “<b>Label :{label}, Value of X:{x}, Value of Y:{y}”,
Work like a charm :) …. Sweett….