You must be logged in to post your query.
Home › Forums › Chart Support › How to fill an array when the data does not exist?
Tagged: PHP Column Charts
hello,
I display a graph with 2 columns in bars for 2023, 2022, 2021…. If I give static data, the graph displays perfectly fine! Unfortunately, I am unable to display data from my database, I am still missing information to properly build my 2 Arrays!
Here is what I did:
while ($data = $requete3->fetch()) { // Hébergement : if ($data['P_TYPE']=="HEBERGEMENT"){ if(isset($annee) AND ($annee-$data['ANNEE']>=1)){ $restauration[] = array("label"=> $data['ANNEE'], "y"=> 0); $annee=''; } else{ $hebergement[] = array("label"=> $data['ANNEE'], "y"=> $data['ca_total']); $annee=$data['ANNEE']; } } // Hébergement : if ($data['P_TYPE']=="RESTAURATION"){ if(isset($annee) AND ($annee-$data['ANNEE']>=1)){ $hebergement[] = array("label"=> $data['ANNEE'], "y"=> 0); $annee=''; } else{ $restauration[] = array("label"=> $data['ANNEE'], "y"=> $data['ca_total']); $annee=$data['ANNEE']; } } }
And this is the print_r : Array ( [0] => Array ( [label] => 2023 [y] => 2200.0000 )
) Array ( [0] => Array ( [label] => 2022 [y] => 0 )
[1] => Array ( [label] => 2022 [y] => 12944.5000 )
) Thanks for your help
@stephem69,
Can you kindly upload a working sample project to Google Drive or Onedrive and share it with us along with a sample database so that we can run it locally to understand the scenario better and help you out?
— Adithya Menon Team CanvasJS
You must be logged in to reply to this topic. Login/Register