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