javascript - how to get array data for highchart basic column?
one text
I have a problem when I want to get array data for the highcart basic column, my case is in the recruitment application I want to display data on the highchart basic column, namely how many applicants register, how many applicants are rejected, and how many applicants are accepted based on a certain period.
I try to retrieve applicant data like sample code below:
// highchart
$priode = Lowongan::select(\DB::raw("DATE_FORMAT(start_priode, '%d-%M-%Y') as tgl"))->orderBy('created_at')->pluck('tgl');
$low = Lowongan::all();
$index = ['Pelamar','Ditolak','Diterima'];
$a = [];
for ($i=0; $i < count($low) ; $i++) {
for ($a=0; $a < count($low) ; $a++) {
if($index[$i] == 'Pelamar'){
$data = Pelamar::select('id_lowongan',DB::raw("COUNT(id_pelamar) AS jumlah"))->where('status', 'r')->where('id_lowongan', $low[$a]['id_lowongan'])->groupBy('id_lowongan')->pluck('jumlah');
}elseif($index[$i] == 'Ditolak'){
$data = Pelamar::select('id_lowongan',DB::raw("COUNT(id_pelamar) AS jumlah"))->where('status', 't')->where('id_lowongan', $low[$a]['id_lowongan'])->groupBy('id_lowongan')->pluck('jumlah');
}else{
$data = Pelamar::select('id_lowongan',DB::raw("COUNT(id_pelamar) AS jumlah"))->where('status', 'l')->where('id_lowongan', $low[$a]['id_lowongan'])->groupBy('id_lowongan')->pluck('jumlah');
}
}
$hasil[] = array(
'name' => $index[$i],
'data' => $data
);
}
echo json_encode($hasil);
exit();
return view('r-admin.dashboard.IndexDashboard', compact('priode', 'hasil'));
the result in json_encode is like this :
[{"name":"Pelamar","data":[2]},{"name":"Ditolak","data":[]},{"name":"Diterima","data":[]}]
the result should be like this :
[{"name":"Pelamar","data":[2,1,2]},{"name":"Ditolak","data":[0,0,0]},{"name":"Diterima","data":[0,0,0]}]
maybe my error is in placing $hasil[], but when I put $hasil[] inside the for($a)..., then the result is like this :
[{"name":"Pelamar","data":[2]},{"name":"Pelamar","data":[1]},{"name":"Pelamar","data":[2]},{"name":"Ditolak","data":[]},{"name":"Ditolak","data":[]},{"name":"Ditolak","data":[]},{"name":"Diterima","data":[]},{"name":"Diterima","data":[]},{"name":"Diterima","data":[]}]
the result will get double data.
Source