mishuk Posted March 26, 2007 Share Posted March 26, 2007 Hi. Using the script below i am trying to populate a bar chart with results from a query instead of static values (these being the values in the commented $data). I have managed to get to a stage where i get two bars, both of student count 9 one with a 0 for the title for the column and the other with SchNo. Can anyone please help? Thanks include ("../includes/db_connect.php"); include('../includes/postgraph.class.php'); $query = "SELECT count(s.school_id) SchNo FROM tbl_school a, tbl_student s WHERE a.school_id = s.school_id GROUP BY s.school_id"; $result = mysql_query($query) or die(mysql_error()); //$data = array(1 => 9, 11, 26, 31, 22, 19, 21, 29, 9, 11, 5, 10, 8, 9, 9); $data = mysql_fetch_array($result); $graph = new PostGraph(350,200); $graph->setGraphTitles('Number of students for each school', 'Schoo', 'Number of Students'); $graph->setYNumberFormat('integer'); $graph->setYTicks(10); $graph->setData($data); $graph->setXTextOrientation('horizontal'); $graph->drawImage(); $graph->printImage(); Quote Link to comment Share on other sites More sharing options...
jguy Posted April 2, 2007 Share Posted April 2, 2007 $data = mysql_fetch_array($result); isn't going to work. All you'll get is "resourceID#1 or something..... You'll need to iterate through your $data array to get the row value for your chart. i.e.: while ($row = mysql_fetch_array($data)){ $data = row[0]; } Then: $graph->setData($data); Might work....haven't used this class b4, so it's just a guess. Quote Link to comment Share on other sites More sharing options...
solarisuser Posted April 6, 2007 Share Posted April 6, 2007 Use jpgraph and look at its examples with MySQL and you'll get it done. Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.