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.
Our community is visited by hundreds of web development professionals every day. Ask your question and get a quick answer for free.
Find the answer in similar questions on our website.
Do you know the answer to this question? Write a quick response to it. With your help, we will make our community stronger.
JavaScript is a multi-paradigm language that supports event-driven, functional, and mandatory (including object-oriented and prototype-based) programming types. Originally JavaScript was only used on the client side. JavaScript is now still used as a server-side programming language. To summarize, we can say that JavaScript is the language of the Internet.
https://www.javascript.com/
Welcome to the Q&A site for web developers. Here you can ask a question about the problem you are facing and get answers from other experts. We have created a user-friendly interface so that you can quickly and free of charge ask a question about a web programming problem. We also invite other experts to join our community and help other members who ask questions. In addition, you can use our search for questions with a solution.
Ask about the real problem you are facing. Describe in detail what you are doing and what you want to achieve.
Our goal is to create a strong community in which everyone will support each other. If you find a question and know the answer to it, help others with your knowledge.