Home Forums Chart Support PHP Foreach loop the dataPoints for Chart

PHP Foreach loop the dataPoints for Chart

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

    Hey, I want to Display a Pie Chart on my Website. The Pie Chart will show the amount of tasks each user has completed from the DB.

    This will change over time, and the amount of users will likely increase as will the amount of tasks each user has completed.

    So I am trying the following,

    
    <?php
    foreach($users as $user):
    $dataPoints = array(
        array("label"=> $user->username, "y"=> 590),
    
    );
    endforeach;
    ?>
    <script>

    However, it is just returning one Username.

    #24762

    @mhiggins,

    Ideally, the code snippet shared above should loop through the variable user values in the $users array. As we are not knowing the exact length of the $users array, can you kindly create a sample project reproducing the issue you are facing and share it with us over Google-Drive or Onedrive so that we can run the sample locally at our end to understand the scenario better and help you out?

    You can also refer to this gallery page for an example on creating a chart using data from the database in PHP.

    PHP Chart Data from Database


    Shashi Ranjan
    Team CanvasJS

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

You must be logged in to reply to this topic.