[ Index ] |
|
Code source de jpGraph 2.2 |
1 <?php 2 // 3 // Example of frequence bar 4 // 5 include_once ("../jpgraph.php"); 6 include_once ("../jpgraph_bar.php"); 7 include_once ("../jpgraph_line.php"); 8 9 // Utility function to calculate the accumulated frequence 10 // for a set of values and ocurrences 11 function accfreq($data) { 12 rsort($data); 13 $s = array_sum($data); 14 $as = array($data[0]); 15 $asp = array(100*$as[0]/$s); 16 $n = count($data); 17 for( $i=1; $i < $n; ++$i ) { 18 $as[$i] = $as[$i-1]+$data[$i]; 19 $asp[$i] = 100.0*$as[$i]/$s; 20 } 21 return $asp; 22 } 23 24 // some data 25 $data_freq = array(22,20,12,10,5,4,2); 26 $data_accfreq = accfreq($data_freq); 27 28 // Create the graph. 29 $graph = new Graph(350,250); 30 31 // Setup some basic graph parameters 32 $graph->SetScale("textlin"); 33 $graph->SetY2Scale('lin',0,100); 34 $graph->img->SetMargin(50,70,30,40); 35 $graph->yaxis->SetTitleMargin(30); 36 $graph->SetMarginColor('#EEEEEE'); 37 38 // Setup titles and fonts 39 $graph->title->Set("Frequence plot"); 40 $graph->xaxis->title->Set("X-title"); 41 $graph->yaxis->title->Set("Y-title"); 42 43 $graph->title->SetFont(FF_FONT1,FS_BOLD); 44 $graph->yaxis->title->SetFont(FF_FONT1,FS_BOLD); 45 $graph->xaxis->title->SetFont(FF_FONT1,FS_BOLD); 46 47 // Turn the tickmarks 48 $graph->xaxis->SetTickSide(SIDE_DOWN); 49 $graph->yaxis->SetTickSide(SIDE_LEFT); 50 51 $graph->y2axis->SetTickSide(SIDE_RIGHT); 52 $graph->y2axis->SetColor('black','blue'); 53 $graph->y2axis->SetLabelFormat('%3d.0%%'); 54 55 // Create a bar pot 56 $bplot = new BarPlot($data_freq); 57 58 // Create accumulative graph 59 $lplot = new LinePlot($data_accfreq); 60 61 // We want the line plot data point in the middle of the bars 62 $lplot->SetBarCenter(); 63 64 // Use transperancy 65 $lplot->SetFillColor('lightblue@0.6'); 66 $lplot->SetColor('blue@0.6'); 67 $graph->AddY2($lplot); 68 69 // Setup the bars 70 $bplot->SetFillColor("orange@0.2"); 71 $bplot->SetValuePos('center'); 72 $bplot->value->SetFormat("%d"); 73 $bplot->value->SetFont(FF_ARIAL,FS_NORMAL,9); 74 $bplot->value->Show(); 75 76 // Add it to the graph 77 $graph->Add($bplot); 78 79 // Send back the HTML page which will call this script again 80 // to retrieve the image. 81 $graph->Stroke(); 82 83 ?>
titre
Description
Corps
titre
Description
Corps
titre
Description
Corps
titre
Corps
Généré le : Sat Nov 24 09:27:55 2007 | par Balluche grâce à PHPXref 0.7 |
![]() |