Home Forums Chart Support How to fill an array when the data does not exist?

How to fill an array when the data does not exist?

Viewing 2 posts - 1 through 2 (of 2 total)
  • #38383

    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

    • This topic was modified 1 year, 8 months ago by stephem69.
    #38396

    @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

Viewing 2 posts - 1 through 2 (of 2 total)

You must be logged in to reply to this topic.