0đź‘Ť
In your controller you call return view('admin.main')->with('userInfo',$user_info);
with('userInfo',$user_info)
sets a $userInfo
variable in your view with the content of $user_info, so just something like that should do the trick
{!! app()->chartbar->render("BarChart", $userInfo) !!}
EDIT: i assumed $user_info was already in the correct format but you couldn’t figure out how to display it. Reading your comments i better understand your needs.
I don’t know which data format chartJS and what you want to display. Looking $data example and your DB query, i assume you want to display data in the format “role_id” => count(*)
so, in that case, i would do something like
$userArray = array();
foreach($user_info as $row) {
$userArray[$row->role_id] = $row->total;
}
return view('admin.main')->with('userInfo',$userArray);
- [Chartjs]-Using chart.js inside node.js
- [Chartjs]-ChartJS – how to display line chart with single element as a line? (not as a dot)
0đź‘Ť
Looks like you need to put the data in the right format:
public function getMainAdminBackend() {
$user_info = \DB::table('users')
->select('role_id', \DB::raw('count(*) as total'))
->groupBy('role_id')
->get();
$data = [];
if ($user_info) {
foreach ($user_info as $month => $value) {
$data[date("M", mktime(0, 0, 0, $month, 1, 0))] = [$value];
}
}
return view('admin.main')->with('userInfo', $data);
}
- [Chartjs]-In Chart.js >3.0, on axis of type time, how to show labels and ticks only for existing data points (make labels reflect data)?
- [Chartjs]-Angular2 and ng2-charts does not display any graph
Source:stackexchange.com