Jump to content

Bar chart


mishuk

Recommended Posts

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();

Link to comment
https://forums.phpfreaks.com/topic/44274-bar-chart/
Share on other sites

$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.

Link to comment
https://forums.phpfreaks.com/topic/44274-bar-chart/#findComment-219932
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.