add amendments metric
[contractdashboard.git] / graphs / displayAgenciesGraph.php
blob:a/graphs/displayAgenciesGraph.php -> blob:b/graphs/displayAgenciesGraph.php
<?php <?php
include_once ("../lib/common.inc.php"); include_once ("../lib/common.inc.php");
$topX = 15; $topX = 15;
$startYear = 2007;  
$query = "SELECT SUM(value) as val, agencyName FROM `contractnotice` WHERE (YEAR(contractStart) >= $startYear) AND childCN = 0 $query = "SELECT SUM(value) as val, agencyName FROM `contractnotice` WHERE (YEAR(contractStart) >= $startYear) AND childCN = 0
GROUP BY agencyName ORDER BY val DESC limit $topX"; GROUP BY agencyName ORDER BY val DESC limit $topX";
$result = mysql_query($query); $result = mysql_query($query);
$agencies = Array(); $agencies = Array();
$values = Array(); $values = Array();
while ($row = mysql_fetch_array($result, MYSQL_BOTH)) { while ($row = mysql_fetch_array($result, MYSQL_BOTH)) {
$agencies[] = $row['agencyName']; $agencies[] = $row['agencyName'];
$values[] = doubleval($row["val"]); $values[] = doubleval($row["val"]);
} }
mysql_free_result($result); mysql_free_result($result);
   
$query = "SELECT sum(a.val) as value, count(1) as count from (SELECT SUM(value) as val, agencyName FROM `contractnotice` WHERE (YEAR(contractStart) >= $startYear) AND childCN = 0 $query = "SELECT sum(a.val) as value, count(1) as count from (SELECT SUM(value) as val, agencyName FROM `contractnotice` WHERE (YEAR(contractStart) >= $startYear) AND childCN = 0
GROUP BY agencyName ORDER BY val DESC LIMIT 18446744073709551610 OFFSET $topX) as a"; GROUP BY agencyName ORDER BY val DESC LIMIT 18446744073709551610 OFFSET $topX) as a";
$result = mysql_query($query); $result = mysql_query($query);
while ($row = mysql_fetch_array($result, MYSQL_BOTH)) { while ($row = mysql_fetch_array($result, MYSQL_BOTH)) {
$agencies[] = $row['count'] . " other agencies"; $agencies[] = $row['count'] . " other agencies";
$values[] = doubleval($row[0]); $values[] = doubleval($row[0]);
} }
mysql_free_result($result); mysql_free_result($result);
   
// Width and height of the graph // Width and height of the graph
$width = 800; $width = 800;
$height = 800; $height = 800;
// Create a graph instance // Create a graph instance
$graph = new PieGraph($width, $height); $graph = new PieGraph($width, $height);
$pieplot = new PiePlot($values); $pieplot = new PiePlot($values);
$pieplot->SetCenter(400, 300); $pieplot->SetCenter(400, 300);
$pieplot->SetGuideLines(true, false); $pieplot->SetGuideLines(true, false);
$pieplot->SetLegends($agencies); $pieplot->SetLegends($agencies);
// Add the plot to the graph // Add the plot to the graph
$graph->Add($pieplot); $graph->Add($pieplot);
$graph->legend->SetPos(0.01, 0.97, 'left', 'bottom'); $graph->legend->SetPos(0.01, 0.97, 'left', 'bottom');
$graph->legend->SetColumns(2); $graph->legend->SetColumns(2);
// Display the graph // Display the graph
$graph->Stroke(); $graph->Stroke();
?> ?>