Codice PHP:
header("Content-type: image/png");
$W = 500;
$H = 400;
$R1= 0.10;
$R2= 0.30;
// SET SCALA MASSIMA
$Scale = $R2 + $R2 / 4;
// SET IMMAGINE
$Margin = 50;
// CREAZIONE IMMAGINE
$img=imagecreate(500, 400);
// ALLOCAZIONE DEI COLORI
$sfondo = @imagecolorallocate ( $img , 245 , 245 , 245 );
$grigio = @imagecolorallocate ( $img , 200 , 200 , 200 );
$nero = @imagecolorallocate ( $img , 0 , 0 , 0 );
$rosso = @imagecolorallocate ( $img , 255 , 0 , 0 );
$verde = @imagecolorallocate ( $img , 0 , 255 , 0 );
// DISEGNO ASSI CARTESIANI
@imageline ( $img , $Margin , 0 , $Margin , $H - $Margin , $nero );
@imageline ( $img , $Margin , $H - $Margin , $W , $H - $Margin , $nero );
// RIDEFINISCO AREA DI STAMPA DEL GRAFICO
$W -= $Margin;
$H -= $Margin;
// STAMPA LINEE GUIDA ORIZZONTALI
$Passo = $Scale / 10 ;
$y = $Passo ;
for ( $j=0 ; $j < 10 ; $j++ )
{
// STAMPA DELLE LINEE DI RIFERIMENTO ORIZZONTALI
@imageline ( $img , $Margin + 1 , $H - ( ( $H * $y ) / $Scale ) , $W + $Margin , $H - ( ( $H * $y ) / $Scale ) , $grigio );
// STAMPA DELLE ETICHETTE DI RIFERIMENTO SULL'ASSE Y
if ( $j < 9 )
@imageString ( $img , 2 , 5 , $H - ( ( $H * $y ) / $Scale ) - 7 , $y , $nero );
// AGGIORNAMENTO DEL PASSO
$y += $Passo;
}
// STAMPA DEL GRAFICO
$Passo = $W / ( count($Values) - 1 ); // SCELTA DEL PASSO SULL'ASSE X IN RELAZIONE AL NUMERO DI ELEMENTI DA RIPORTARE
$x = $Margin ; // PUNTO DI INIZIO PER L'ASSE X
for ( $j=0 ; $j < count($Values) ; $j++ )
{
// STAMPA DELLA GRIGLIA VERTICALE E DELL' ETICHETTA SULL'ASSE X
if ( $j > 0 )
{
@imageline ( $img , $x , 0 , $x , $H - 1 , $grigio );
@imageString ( $img , 2 , $x , $H , $j , $nero );
}
// STAMPA DEL PUNTO DI RIFERIMENTO DEL VALORE
@imagefilledarc ( $img , $x , $H - ( ( $H * $Values[$j] ) / $Scale ) , 6 , 6 , 0, 360 , $nero , IMG_ARC_PIE );
// AGGIORNAMENTO DELL'ASSE DELLE X
$x += $Passo;
// STAMPA DELLA LINEA DI INTERPOLAZIONE
if ( $j < count($Values)-1 )
@imageline( $img , $x - $Passo , $H - ( ( $H * $Values[$j] ) / $Scale ) , $x , $H - ( ( $H * $Values[$j+1] ) / $Scale ) , $nero );
}
// STAMPA LINEE DI RIFERIMENTO
@imageline($img , $Margin + 1 , $H - ( ( $H * $R1 ) / $Scale ) , $W + $Margin , $H - ( ( $H * $R1 ) / $Scale ) , $verde );
@imageline($img , $Margin + 1 , $H - ( ( $H * $R2 ) / $Scale ) , $W + $Margin , $H - ( ( $H * $R2 ) / $Scale ) , $rosso );
// SALVATAGGIO IMMAGINE E DEALLOCAZIONE DELLA MEMORIA UTILIZZATA
@imagePng ( $img );
@imagedestroy ( $img );
echo '[img]fx_GRAPH_LINE.php[/img]';