this is my function in my controller
public function stat(ChartBuilderInterface $chartBuilder): Response
{
//livreur par nbr livraison
$livreur = $this->getDoctrine()->getRepository(Livreur::class)->findAll();
$livreurNom = [];
$all=[];
$numlivraisons=[];
foreach($livreur as $l){
$entityManager = $this->getDoctrine()->getManager();
$query = $entityManager->createQuery(
'SELECT c.nomlivreur ,COUNT(l)
FROM App\Entity\Livraison l
JOIN l.idLivreur c
WHERE l.idLivreur = :id'
)
->setParameter('id', $l->getIdlivreur());
$all[]=$query->getResult();
}
foreach($all as $l){
$livreurNom[]=array_column($l, "nomlivreur");
$numlivraisons[]=array_column($l, "1");
$values[]=array_column($l, "nomlivreur","1") ;
}
and this is my template
var chart = document.getElementById("nbrlivparlivreur");
let nbrlivparlivreur = new Chart(chart, {
type: 'bar',
data: {
labels: {{l | raw}},
datasets: [{
label: "nombres de livraison",
backgroundColor: "#4e73df",
hoverBackgroundColor: "#2e59d9",
borderColor: "#4e73df",
data: {{num | json_encode | raw}},
}],
},
});
i get the data correctly from the database and organized but when i put it in the chart it become not organized as needed