I'm trying to create a chart of all of our tickets from our helpdesk software based on the month/year that they came in. I have ran the query against the database and am getting exactly what I'm looking for.
I've found PHPGraphlib to generate charts based on an array entered. However I'm getting constant errors that the Graph is either too small or too many datapoints.
Error:
I know it's generating the array correctly because I am able to view the contents via:
print_r($data);
Output of print_r($data);
Array ( [March 2012] => 10 [April 2012] => 18 [May 2012] => 20 [June 2012] => 19 [July 2012] => 10 [August 2012] => 22 [September 2012] => 18 [October 2012] => 17 [November 2012] => 15 [December 2012] => 12 [January 2013] => 24 [February 2013] => 18 [March 2013] => 33 [April 2013] => 13 [May 2013] => 20 [June 2013] => 20 [July 2013] => 21 [August 2013] => 13 [September 2013] => 15 [October 2013] => 14 [November 2013] => 14 [December 2013] => 3 [January 2014] => 13 [February 2014] => 15 [March 2014] => 23 [April 2014] => 20 [May 2014] => 33 [June 2014] => 19 )
.
<?php
include("../phpgraphlib.php");
$graph = new PHPGraphLib(1000,1000);
include 'db.inc';
$sql="SELECT FROM_UNIXTIME(swtickets.dateline,'%M %Y') AS Month, Count(DISTINCT(ticketmaskid)) AS Count FROM swtickets GROUP BY FROM_UNIXTIME(swtickets.dateline,'%M %Y') ORDER BY FROM_UNIXTIME(swtickets.dateline,'%Y'), FROM_UNIXTIME(swtickets.dateline,'%m') ASC";
$result=mysql_query($sql);
$data = array();
$num=mysql_numrows($result);
$i=0;
while ($i < $num){
$mon=mysql_result($result,$i,"Month");
$co=mysql_result($result,$i,"Count");
$data[$mon]=$co;
$i++;
}
mysql_close();
$graph->addData($data);
$graph->setBarColor('255,255,204');
$graph->setTitle('Money Made at XYZ Corp');
$graph->setTextColor('gray');
$graph->createGraph();
?>
I've also tried limiting my Query to just include 1 datapoint and it still generates the same error.
If I create the Array manually it doesn't generate the error and generates the graph as expected.
<?php
include("../phpgraphlib.php");
$graph = new PHPGraphLib(5000,5000);
$data = array(
"March 2012" => "10",
"April 2012" => "18",
"May 2012" => "20",
"June 2012" => "19",
"July 2012" => "10",
"August 2012" => "22",
"September 2012" => "18",
"October 2012" => "17",
"November 2012" => "15",
"December 2012" => "12",
"January 2013" => "24",
"February 2013" => "18",
"March 2013" => "33",
"April 2013" => "13",
"May 2013" => "20",
"June 2013" => "20",
"July 2013" => "21",
"August 2013" => "13",
"September 2013" => "15",
"October 2013" => "14",
"November 2013" => "14",
"December 2013" => "3",
"January 2014" => "13",
"February 2014" => "15",
"March 2014" => "23",
"April 2014" => "20",
"May 2014" => "33",
"June 2014" => "19",
);
$graph->addData($data);
$graph->setBarColor('255,255,204');
$graph->setTitle('Money Made at XYZ Corp');
$graph->setTextColor('gray');
$graph->createGraph();
?>
Output Page: I've tried it on a standard PHP page and an HTML page however receive the same result.
<!DOCTYPE html>
<html>
<head>
<title></title>
</head>
<body>
<img src="graphs/alltickets.php" />
</body>
</html>
Any ideas? Also would you recommend any other free graphing libraries for PHP?