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