updated update script and merged lobbylens admin scripts
[contractdashboard.git] / graphs / displayAgenciesGraph.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
<?php
include_once ("../lib/common.inc.php");
$topX = 15;
$startYear = 2007;
$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";
$result = mysql_query($query);
$agencies = Array();
$values = Array();
while ($row = mysql_fetch_array($result, MYSQL_BOTH)) {
  $agencies[] = $row['agencyName'];
  $values[] = doubleval($row["val"]);
}
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
GROUP BY agencyName ORDER BY val DESC LIMIT 18446744073709551610 OFFSET $topX) as a";
$result = mysql_query($query);
while ($row = mysql_fetch_array($result, MYSQL_BOTH)) {
  $agencies[] = $row['count'] . " other agencies";
  $values[] = doubleval($row[0]);
}
mysql_free_result($result);
 
// Width and height of the graph
$width = 800;
$height = 800;
// Create a graph instance
$graph = new PieGraph($width, $height);
$pieplot = new PiePlot($values);
$pieplot->SetCenter(400, 300);
$pieplot->SetGuideLines(true, false);
$pieplot->SetLegends($agencies);
// Add the plot to the graph
$graph->Add($pieplot);
$graph->legend->SetPos(0.01, 0.97, 'left', 'bottom');
$graph->legend->SetColumns(2);
// Display the graph
$graph->Stroke();
?>