File: C:/xampp/htdocs/PBN/PSASID/graphFix4.php
<?php
# ------- The graph values in the form of associative array
function GenGraph4 ($c1,$c2,$c3,$c4,$c5,$c6,$c7,$c8,$c9,$c10,$c11,$c12,$c13,$c14,$c15,$c16,$c17,$c18,$c19,$c20,$c21,$c22,$c23,$c24,$c25,$c26,$c27,$c28,$c29,$c30) {
$values=array(
"1" => $c1,
"2" => $c2,
"3" => $c3,
"4" => $c4,
"5" => $c5,
"6" => $c6,
"7" => $c7,
"8" => $c8,
"9" => $c9,
"10" => $c10,
"11" => $c11,
"12" => $c12,
"13" => $c13,
"14" => $c14,
"15" => $c15,
"16" => $c16,
"17" => $c17,
"18" => $c18,
"19" => $c19,
"20" => $c20,
"21" => $c21,
"22" => $c22,
"23" => $c23,
"24" => $c24,
"25" => $c25,
"26" => $c26,
"27" => $c27,
"28" => $c28,
"29" => $c29,
"30" => $c30
);
$img_width=1280;
$img_height=200;
$margins=20;
# ---- Find the size of graph by substracting the size of borders
$graph_width=$img_width - $margins * 2;
$graph_height=$img_height - $margins * 2;
$graph_height50T=$img_height/2 - $margins ;
$img=imagecreate($img_width,$img_height);
$bar_width=30;
$total_bars=count($values);
$gap= ($graph_width- $total_bars * $bar_width ) / ($total_bars +1);
# ------- Define Colors ----------------
$bar_color=imagecolorallocate($img,232,214,4);
$key_color=imagecolorallocate($img,0,0,0);
$background_color=imagecolorallocate($img,240,240,255);
$border_color=imagecolorallocate($img,200,200,200);
$line_color=imagecolorallocate($img,220,220,220);
# ------ Create the border around the graph ------
imagefilledrectangle($img,1,1,$img_width-2,$img_height-2,$border_color);
imagefilledrectangle($img,$margins,$margins,$img_width-1-$margins,$img_height-1-$margins,$background_color);
# ------- Max value is required to adjust the scale -------
$max_value=max($values);
$min_value=min($values);
$ratio= $graph_height/(0.3)/2;
# -------- Create scale and draw horizontal lines --------
$horizontal_lines=20;
$horizontal_gap=$graph_height/$horizontal_lines;
for($i=0;$i<=$horizontal_lines;$i++){
$y=$img_height - $margins - $horizontal_gap * $i ;
imageline($img,$margins,$y,$img_width-$margins,$y,$line_color);
$v=intval($horizontal_gap * $i /$ratio);
imagestring($img,0,5,$y-5,$v,$bar_color);
}
# ----------- Draw the bars here ------
for($i=0;$i< $total_bars; $i++){
# ------ Extract key and value pair from the current pointer position
list($key,$value)=each($values);
$x1= $margins + $gap + $i * ($gap+$bar_width) ;
$x2= $x1 + $bar_width;
//$y1=$margins +$graph_height- intval($value * $ratio) ;
//$y1=$margins +$graph_height- intval($value * $ratio) ;
$y1=$margins +$graph_height- intval($value * $ratio) -80;
$y2=$img_height-$margins-80;
imagestring($img,0,$x1+3,$y1-10,$value,$key_color);
imagestring($img,5,$x1+3,$img_height-15,$key,$key_color);
imagefilledrectangle($img,$x1,$y1,$x2,$y2,$bar_color);
}
//header("Content-type:image/png");
//imagepng($img);
imagegif( $img, "graph4.gif", 100);
imagedestroy($img);
echo "";
}
?>