fix value/sum
[contractdashboard.git] / graphs / displayContractStartingGraph.php
blob:a/graphs/displayContractStartingGraph.php -> blob:b/graphs/displayContractStartingGraph.php
<?php <?php
include_once("../lib/common.inc.php"); include_once("../lib/common.inc.php");
$query = "SELECT YEAR(contractStart), MONTH(contractStart), $query = "SELECT YEAR(contractStart), MONTH(contractStart),
value, count(1) as count FROM `contractnotice` SUM(value) as val, count(1) as count FROM `contractnotice`
WHERE (YEAR(contractStart) >= 2008) WHERE (YEAR(contractStart) >= 2008)
AND childCN = 0 AND childCN = 0
GROUP BY MONTH(contractStart), YEAR(contractStart) GROUP BY MONTH(contractStart), YEAR(contractStart)
ORDER BY YEAR(contractStart), MONTH(contractStart)"; ORDER BY YEAR(contractStart), MONTH(contractStart)";
$result = mysql_query($query); $result = mysql_query($query);
$dates = Array(); $dates = Array();
$values = Array(); $values = Array();
while ($row = mysql_fetch_array($result, MYSQL_BOTH)) { while ($row = mysql_fetch_array($result, MYSQL_BOTH)) {
setlocale(LC_MONETARY, 'en_US'); setlocale(LC_MONETARY, 'en_US');
$value = number_format(doubleval($row["value"]),2); $value = number_format(doubleval($row["val"]),2);
$month_name = date( 'F', mktime(0, 0, 0, $row[1]) ); $month_name = date( 'F', mktime(0, 0, 0, $row[1]) );
$dates[] = $month_name." {$row[0]}"; $dates[] = $month_name." {$row[0]}";
$counts[] = doubleval($row["count"]); $counts[] = doubleval($row["count"]);
$values[] = doubleval($row["value"]); $values[] = doubleval($row["val"]);
} }
mysql_free_result($result); mysql_free_result($result);
// Width and height of the graph // Width and height of the graph
$width = 1000; $height = 400; $width = 1000; $height = 400;
// Create a graph instance // Create a graph instance
$graph = new Graph($width,$height); $graph = new Graph($width,$height);
$graph->SetMargin(85,45,45,115); $graph->SetMargin(85,45,45,115);
// Specify what scale we want to use, // Specify what scale we want to use,
$graph->SetScale('textlog'); $graph->SetScale('textlog');
// Setup a title for the graph // Setup a title for the graph
$graph->title->Set('Contracts Starting - All Agencies since July 2008'); $graph->title->Set('Contracts Starting - All Agencies since July 2008');
$graph->SetUserFont("liberation/LiberationSans-Regular.ttf"); $graph->SetUserFont("liberation/LiberationSans-Regular.ttf");
$graph->title->SetFont(FF_USERFONT,FS_NORMAL,12); $graph->title->SetFont(FF_USERFONT,FS_NORMAL,12);
// Setup font for axis // Setup font for axis
$graph->xaxis->SetFont(FF_USERFONT,FS_NORMAL,10); $graph->xaxis->SetFont(FF_USERFONT,FS_NORMAL,10);
$graph->yaxis->SetFont(FF_USERFONT,FS_NORMAL,10); $graph->yaxis->SetFont(FF_USERFONT,FS_NORMAL,10);
// Setup titles and X-axis labels // Setup titles and X-axis labels
$graph->xaxis->SetTickLabels($dates); $graph->xaxis->SetTickLabels($dates);
$graph->xaxis->SetLabelAngle(50); $graph->xaxis->SetLabelAngle(50);
// Create the linear plot // Create the linear plot
$valueplot=new LinePlot($values); $valueplot=new LinePlot($values);
$valueplot->SetFillColor('orange@0.5'); $valueplot->SetFillColor('orange@0.5');
$valueplot->SetLegend("Total Value"); $valueplot->SetLegend("Total Value");
$countplot=new LinePlot($counts); $countplot=new LinePlot($counts);
$countplot->SetFillColor('red@0.5'); $countplot->SetFillColor('red@0.5');
$countplot->SetLegend("Number of Contracts"); $countplot->SetLegend("Number of Contracts");
// Add the plot to the graph // Add the plot to the graph
$graph->Add($valueplot); $graph->Add($valueplot);
$graph->SetYScale(0,'lin'); $graph->SetYScale(0,'lin');
$graph->ynaxis[0]->SetColor('red'); $graph->ynaxis[0]->SetColor('red');
$graph->AddY(0,$countplot); $graph->AddY(0,$countplot);
// Display the graph // Display the graph
$graph->Stroke(); $graph->Stroke();
?> ?>