You must be logged in to post your query.
Home › Forums › Chart Support › PHP Foreach loop the dataPoints for Chart
Tagged: array, Codeigniter, Foreach, php, PieChart
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.
@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?
user
$users
You can also refer to this gallery page for an example on creating a chart using data from the database in PHP.
— Shashi Ranjan Team CanvasJS
You must be logged in to reply to this topic. Login/Register