source: trunk/client/modules/Elezioni/grafici/barre.php@ 113

Last change on this file since 113 was 105, checked in by eol, 13 years ago

Sistemazione elementi grafici e di esportazione dati, stemma sui grafici (var nel config.php $ins_logo=0 per eliminare lo stemma).

File size: 3.7 KB
RevLine 
[22]1<?php
2/************************************************************************/
3/* Eleonline - Raccolta e diffusione dei dati elettorali */
4/* by Luciano Apolito & Roberto Gigli */
5/* http://www.eleonline.it */
6/* info@eleonline.it luciano@aniene.net rgigli@libero.it */
7/************************************************************************/
8
9include ("jpgraph.php");
10include ("jpgraph_bar.php");
11if(file_exists(TTF_DIR))
12 define("CURFONT1",FF_DV_SANSSERIF);
13else
14 define ("CURFONT1",FF_FONT1);
15
16$dati1=$_GET['dati1'];$dati2=$_GET['dati2'];$i=$_GET['i'];$l=$_GET['l'];$w=$_GET['w'];
17$titolo=$_GET['titolo'];$descr=$_GET['descr'];$cop=$_GET['cop'];
18$logo=$_GET['logo'];
19$datay=unserialize(stripslashes($dati1)); // percentuali
20$datax=unserialize(stripslashes($dati2)); // candidati
21
22
23// $i= numero candidati
24// $larghezza label
25if (!isset($l)) $l=180;
26if (!isset($w)) $w=500;
27if ($l=='') $l=180;
28if ($w=='') $w=500;
29
30// Size of graph
31$width=$w;
32$height=$i*30;
33
34// Set the basic parameters of the graph
35$graph = new Graph($width,$height,'auto');
36$graph->SetScale("textlin");
37
38$top = 50;
39$bottom = 80;
40$left = $l;
41$right = 40;
42$graph->Set90AndMargin($left,$right,$top,$bottom);
[105]43//$graph->SetBackgroundImage("../images/$logo",BGIMG_COPY);
44
[22]45$graph->SetShadow();
[105]46$graph->SetBackgroundGradient('yellow','white',GRAD_HOR,BGRAD_MARGIN);
47//$graph->SetBackgroundImage("../images/$logo",BGIMG_COPY);
[22]48// Setup title
49$graph->title->Set("$titolo");
50$graph->title->SetFont(CURFONT1,FS_BOLD,10);
51$graph->subtitle->Set("$descr");
52
53// Setup X-axis
54$graph->xaxis->SetTickLabels($datax);
55$graph->xaxis->SetFont(CURFONT1,FS_BOLD,8);
56$graph->xaxis->SetColor("black","darkred");
57// Some extra margin looks nicer
58$graph->xaxis->SetLabelMargin(5);
59
60// Label align for X-axis
61$graph->xaxis->SetLabelAlign('right','center');
62
63// Add some grace to y-axis so the bars doesn't go
64// all the way to the end of the plot area
65$graph->yaxis->scale->SetGrace(20);
66
67// Setup the Y-axis to be displayed in the bottom of the
68// graph. We also finetune the exact layout of the title,
69// ticks and labels to make them look nice.
70$graph->yaxis->SetPos('max');
71
72// First make the labels look right
73$graph->yaxis->SetLabelAlign('center','top');
74$graph->yaxis->SetLabelFormat('%d');
75$graph->yaxis->SetLabelSide(SIDE_RIGHT);
76
77// The fix the tick marks
78$graph->yaxis->SetTickSide(SIDE_LEFT);
79
80// Finally setup the title
81$graph->yaxis->SetTitleSide(SIDE_RIGHT);
82$graph->yaxis->SetTitleMargin(35);
83
84// To align the title to the right use :
85$graph->yaxis->SetTitle("$cop",'high');
86$graph->yaxis->title->Align('right');
87$graph->yaxis->SetColor("black","darkred");
88// To center the title use :
89//$graph->yaxis->SetTitle('Turnaround 2002','center');
90//$graph->yaxis->title->Align('center');
91
92$graph->yaxis->title->SetFont(CURFONT1,FS_BOLD,12);
93$graph->yaxis->title->SetAngle(0);
94
95
96
97$graph->yaxis->SetFont(CURFONT1,FS_NORMAL); #era FF_FONT2
98// If you want the labels at an angle other than 0 or 90
99// you need to use TTF fonts
100//$graph->yaxis->SetLabelAngle(0);
101
102/*
103// testo
104$txt =new Text("$cop");
105$txt->Pos( 100,$i*29);
106$txt->SetColor( "red");
107$graph->AddText( $txt);
108*/
109
110
111
112
113
114
115
116
117// Now create a bar pot
118$bplot = new BarPlot($datay);
[105]119$bplot->SetFillColor("red");
[22]120$bplot->SetShadow();
121
122//You can change the width of the bars if you like
123$bplot->SetWidth(0.1);
124
125// We want to display the value of each bar at the top
126$bplot->value->Show();
[105]127$bplot->value->SetFont(CURFONT1,FS_BOLD,14);
[22]128$bplot->value->SetAlign('left','center');
[105]129$bplot->value->SetColor("red","yellow");
[64]130$bplot->value->SetFormat("%.2f %%"); # &#37;");
[22]131
132// Add the bar to the graph
133$graph->Add($bplot);
134
135
136$graph->Stroke();
137?>
Note: See TracBrowser for help on using the repository browser.