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 |
|
---|
9 | include ("jpgraph.php");
|
---|
10 | include ("jpgraph_bar.php");
|
---|
11 | if(file_exists(TTF_DIR))
|
---|
12 | define("CURFONT1",FF_DV_SANSSERIF);
|
---|
13 | else
|
---|
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
|
---|
25 | if (!isset($l)) $l=180;
|
---|
26 | if (!isset($w)) $w=500;
|
---|
27 | if ($l=='') $l=180;
|
---|
28 | if ($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);
|
---|
43 | #if(isset($logo)) $graph->SetBackgroundImage("../images/".$logo.".png",BGIMG_COPY);
|
---|
44 | #else
|
---|
45 | //$graph->SetBackgroundImage("../images/vuoto.jpg",BGIMG_COPY);
|
---|
46 | // Nice shadow
|
---|
47 | $graph->SetShadow();
|
---|
48 | $graph->SetBackgroundGradient('white','yellow',GRAD_HOR,BGRAD_MARGIN);
|
---|
49 | // Setup title
|
---|
50 | $graph->title->Set("$titolo");
|
---|
51 | $graph->title->SetFont(CURFONT1,FS_BOLD,10);
|
---|
52 | $graph->subtitle->Set("$descr");
|
---|
53 |
|
---|
54 | // Setup X-axis
|
---|
55 | $graph->xaxis->SetTickLabels($datax);
|
---|
56 | $graph->xaxis->SetFont(CURFONT1,FS_BOLD,8);
|
---|
57 | $graph->xaxis->SetColor("black","darkred");
|
---|
58 | // Some extra margin looks nicer
|
---|
59 | $graph->xaxis->SetLabelMargin(5);
|
---|
60 |
|
---|
61 | // Label align for X-axis
|
---|
62 | $graph->xaxis->SetLabelAlign('right','center');
|
---|
63 |
|
---|
64 | // Add some grace to y-axis so the bars doesn't go
|
---|
65 | // all the way to the end of the plot area
|
---|
66 | $graph->yaxis->scale->SetGrace(20);
|
---|
67 |
|
---|
68 | // Setup the Y-axis to be displayed in the bottom of the
|
---|
69 | // graph. We also finetune the exact layout of the title,
|
---|
70 | // ticks and labels to make them look nice.
|
---|
71 | $graph->yaxis->SetPos('max');
|
---|
72 |
|
---|
73 | // First make the labels look right
|
---|
74 | $graph->yaxis->SetLabelAlign('center','top');
|
---|
75 | $graph->yaxis->SetLabelFormat('%d');
|
---|
76 | $graph->yaxis->SetLabelSide(SIDE_RIGHT);
|
---|
77 |
|
---|
78 | // The fix the tick marks
|
---|
79 | $graph->yaxis->SetTickSide(SIDE_LEFT);
|
---|
80 |
|
---|
81 | // Finally setup the title
|
---|
82 | $graph->yaxis->SetTitleSide(SIDE_RIGHT);
|
---|
83 | $graph->yaxis->SetTitleMargin(35);
|
---|
84 |
|
---|
85 | // To align the title to the right use :
|
---|
86 | $graph->yaxis->SetTitle("$cop",'high');
|
---|
87 | $graph->yaxis->title->Align('right');
|
---|
88 | $graph->yaxis->SetColor("black","darkred");
|
---|
89 | // To center the title use :
|
---|
90 | //$graph->yaxis->SetTitle('Turnaround 2002','center');
|
---|
91 | //$graph->yaxis->title->Align('center');
|
---|
92 |
|
---|
93 | $graph->yaxis->title->SetFont(CURFONT1,FS_BOLD,12);
|
---|
94 | $graph->yaxis->title->SetAngle(0);
|
---|
95 |
|
---|
96 |
|
---|
97 |
|
---|
98 | $graph->yaxis->SetFont(CURFONT1,FS_NORMAL); #era FF_FONT2
|
---|
99 | // If you want the labels at an angle other than 0 or 90
|
---|
100 | // you need to use TTF fonts
|
---|
101 | //$graph->yaxis->SetLabelAngle(0);
|
---|
102 |
|
---|
103 | /*
|
---|
104 | // testo
|
---|
105 | $txt =new Text("$cop");
|
---|
106 | $txt->Pos( 100,$i*29);
|
---|
107 | $txt->SetColor( "red");
|
---|
108 | $graph->AddText( $txt);
|
---|
109 | */
|
---|
110 |
|
---|
111 |
|
---|
112 |
|
---|
113 |
|
---|
114 |
|
---|
115 |
|
---|
116 |
|
---|
117 |
|
---|
118 | // Now create a bar pot
|
---|
119 | $bplot = new BarPlot($datay);
|
---|
120 | $bplot->SetFillColor("orange");
|
---|
121 | $bplot->SetShadow();
|
---|
122 |
|
---|
123 | //You can change the width of the bars if you like
|
---|
124 | $bplot->SetWidth(0.1);
|
---|
125 |
|
---|
126 | // We want to display the value of each bar at the top
|
---|
127 | $bplot->value->Show();
|
---|
128 | $bplot->value->SetFont(CURFONT1,FS_BOLD,12);
|
---|
129 | $bplot->value->SetAlign('left','center');
|
---|
130 | $bplot->value->SetColor("black","darkred");
|
---|
131 | $bplot->value->SetFormat("%.2f %");
|
---|
132 |
|
---|
133 | // Add the bar to the graph
|
---|
134 | $graph->Add($bplot);
|
---|
135 |
|
---|
136 |
|
---|
137 | $graph->Stroke();
|
---|
138 | ?>
|
---|