File: C:/xampp/htdocs/Fogra778/graphFixB3.php
<?php
# ------- The graph values in the form of associative array
function GenGraphB3 ($s1,$s2,$s3,$s4,$s5,$s6,$s7,$s8,$s9,$s10,$d1,$d2,$d3,$d4,$d5,$d6,$d7,$d8,$d9,$d10,$g1,$g2,$g3,$g4,$g5,$g6,$g7,$g8,$c1,$c2,$c3,$c4,$c5,$c6,$c7,$c8) {
$values=array(
"5" => $s1,
"6" => ($s1+$s2)/2,
"7" => $s2,
"8" => ($s3*0.33+$s2*0.66),
"9" => ($s3*0.66+$s2*0.33),
"10" => $s3,
"11" => ($s3+$s4)/2,
"12" => $s4,
"13" => ($s5*0.33+$s4*0.66),
"14" => ($s5*0.66+$s4*0.33),
"15" => $s5,
"16" => ($s5+$s6)/2,
"17" => $s6,
"18" => ($s6*0.66+$s7*0.33),
"19" => ($s6*0.33+$s7*0.66),
"20" => $s7,
"21" => ($s7+$s8)/2,
"22" => $s8,
"23" => ($s8+$s9)/2,
"24" => $s9,
"25" => ($s9*0.66+$s10*0.33),
"26" => ($s9*0.33+$s10*0.66),
"27" => $s10,
"34" => $d1,
"35" => ($d1+$d2)/2,
"36" => $d2,
"37" => ($d3*0.33+$d2*0.66),
"38" => ($d2*0.33+$d3*0.66),
"39" => $d3,
"40" => ($d3*0.5+$d4*0.5),
"41" => $d4,
"42" => ($d5*0.33+$d4*0.66),
"43" => ($d4*0.33+$d5*0.66),
"44" => $d5,
"45" => ($d5*0.5+$d6*0.5),
"46" => $d6,
"47" => ($d7*0.33+$d6*0.66),
"48" => ($d6*0.33+$d7*0.66),
"49" => $d7,
"50" => ($d7*0.5+$d8*0.5),
"51" => $d8,
"52" => ($d8*0.5+$d9*0.5),
"53" => $d9,
"54" => ($d10*0.33+$d9*0.66),
"55" => ($d9*0.33+$d10*0.66),
"56" => $d10,
"61" => $g1,
"62" => $g1,
"63" => $g1,
"64" => ($g1*0.5+$g2*0.5),
"65" => $g2,
"66" => ($g3*0.5+$g2*0.5),
"67" => $g3,
"68" => ($g4*0.33+$g3*0.77),
"69" => ($g4*0.66+$g3*0.33),
"70" => $g4,
"71" => ($g4*0.75+$g5*0.25),
"72" => ($g4*0.5+$g5*0.5),
"73" => ($g4*0.25+$g3*0.75),
"74" => $g5,
"75" => ($g6*0.33+$g5*0.66),
"76" => ($g6*0.66+$g5*0.33),
"77" => $g6,
"78" => ($g6*0.5+$g7*0.5),
"79" => $g7,
"80" => ($g7*0.5+$g8*0.5),
"81" => $g8,
"82" => $g8,
"83" => $g8,
"91" => $c1,
"92" => $c1,
"93" => $c1,
"94" => $c1,
"95" => $c2,
"96" => $c2,
"97" => $c3,
"98" => $c3,
"99" => $c3,
"100" => $c4,
"101" => $c4,
"102" =>$c4,
"103" => $c4,
"104" => $c5,
"105" => $c5,
"106" => $c5,
"107" => $c6,
"108" => $c6,
"109" => $c7,
"100" => $c7,
"111" => $c8,
"112" => $c8,
"113" => $c8,
);
$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)/4;
$gap= ($graph_width- $total_bars * $bar_width ) / ($total_bars +1);
# ------- Define Colors ----------------
//$bar_color=imagecolorallocate($img,64,64,64);
$bar_color=imagecolorallocate($img,53,117,6);
$key_color=imagecolorallocate($img,0,0,0);
$background_color=imagecolorallocate($img,240,240,255);
$border_color=imagecolorallocate($img,200,200,0);
$line_color=imagecolorallocate($img,220,220,220);
$red_line=imagecolorallocate($img,255,0,0);
$yellow_line=imagecolorallocate($img,235,235,0);
$green_line=imagecolorallocate($img,0,185,0);
# ------ 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++){
if ($i==8) {
$y=$img_height - $margins - $horizontal_gap * $i ;
imageline($img,$margins,$y,$img_width-$margins,$y,$red_line);
$v=intval($horizontal_gap * $i /$ratio);
imagestring($img,0,5,$y-5,$v,$bar_color);}
elseif ($i==10) {
$y=$img_height - $margins - $horizontal_gap * $i ;
imageline($img,$margins,$y,$img_width-$margins,$y,$green_line);
$v=intval($horizontal_gap * $i /$ratio);
imagestring($img,0,5,$y-5,$v,$bar_color);}
elseif ($i==12) {
$y=$img_height - $margins - $horizontal_gap * $i ;
imageline($img,$margins,$y,$img_width-$margins,$y,$red_line);
$v=intval($horizontal_gap * $i /$ratio);
imagestring($img,0,5,$y-5,$v,$bar_color);}
else {
$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< 23; $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) -80;
$y2=$img_height-$margins-80;
if ($value>0 and $values[$i+34]<5) {
imagestring($img,0,$x1+3,$y1-10,round($value,2),$key_color);
imagestring($img,5,$x1+3,$img_height-15,$key,$bar_color);
imagefilledrectangle($img,$x1,$y1,$x2,$y2,$bar_color);
}
elseif ($value>0 and $values[$i+34]>5) {
imagestring($img,0,$x1+3,$y1-10,round($value,2),$red_line);
imagestring($img,5,$x1+3,$img_height-15,$key,$bar_color);
imagefilledrectangle($img,$x1,$y1,$x2,$y2,$red_line);
}
elseif ($value<0 and $values[$i+34]<5) {
//echo "d value:".($i+34)."-".$values[$i+34];
imagestring($img,0,$x1+3,$y1+7,round($value,2),$key_color);
imagestring($img,5,$x1+3,$img_height-15,$key,$bar_color);
imagefilledrectangle($img,$x1,$y1,$x2,$y2,$bar_color);
if ($values[$i+91]==6) {
echo "value 61:".$values[$i+61];
imagefilledrectangle($img,$x2-6,$y2,$x2+12,$y2-$values[$i+61]*10,$yellow_line); }
}
elseif ($value<0 and $values[$i+34]>5) {
//echo "_ud value:".($i+34)."-".$values[$i+34];
imagestring($img,0,$x1+3,$y1+7,round($value,2),$red_line);
imagestring($img,5,$x1+3,$img_height-15,$key,$bar_color);
imagefilledrectangle($img,$x1,$y1,$x2,$y2,$red_line);
}
//imagestring($img,5,$x1+3,$img_height-15,$key,$bar_color);
//imagefilledrectangle($img,$x1,$y1,$x2,$y2,$bar_color);
}
//header("Content-type:image/png");
//imagepng($img);
imagegif( $img, "graphB3.gif", 100);
imagedestroy($img);
echo "";
}
?>