I have this mysql table with "date" and "sum" columns. The date has format YYYY-MM-DD and sum only contains numbers.

I than use phpgraphlib to draw a graph defined by the date column. For instanse I want to see the sum for year 2007, grouped by months. This is OK, this I can do. But, how do I implement it with phpgraphlib? (http://www.ebrueggeman.com/phpgraphlib/)

For example, when I run the query
$sql="SELECT YEAR(date) as year, MONTH(date) as month, SUM(sum) AS sum FROM transactions GROUP BY month";
I get the month number, 1 for january, and than a sum for transactions made that month.

How can I get this sum into the corrensponding month in the below $data array?

include("phpgraphlib.php");
$graph=new PHPGraphLib(550,350);
$data=array("Jan"=>-10.1, "Feb"=>-3.6, "Mar"=>11.0, "Apr"=>30.7, "May"=>48.6, "Jun"=>59.8, "Jul"=>62.5, "Aug"=>56.8, "Sep"=>45.5, "Oct"=>25.1, "Nov"=>2.7, "Dec"=>-6.5);
$graph->addData($data);
$graph->setBarColor("navy");
$graph->setupXAxis(20, "blue");
$graph->setTitle("Average Temperature by Month, in Fairbanks Alaska");
$graph->setTitleColor("blue");
$graph->setGridColor("153,204,255");
$graph->setDataValues(true);
$graph->setDataValueColor("navy");
$graph->createGraph();

Any help with this would be very much appreciated!

*Edit: Typos

    Write a Reply...