The script below is a sample on how to create a bar graph using PHP language.
$arr_value = array(1 => 10, 2 => 20, 3 => 30, 4 => 40, 5 => 50);
/* image size and margin */
$img_height = 400;
$img_width = 600;
$margins = 20;
/* size of the graph – subtracting the size of borders */
$graph_width = $img_width – $margins * 2;
$graph_height = $img_height – $margins * 2;
$imageObj = imagecreate($img_width,$img_height); //create the image
/* define the width of the bar */
$bar_width = 20;
$total_bars = count($arr_value); //number of bars
//in – between spaces of the bar graph
$gap = ($graph_width – $total_bars * $bar_width)/($total_bars + 1);
/* define the colors which will be used for bars, backgrounds, lines and borders */
//int imagecollorallocate(image, int red, int green, int blue)
$bar_color = imagecolorallocate($imageObj,0,64,128);
$background_color = imagecolorallocate($imageObj,240,240,255);
$border_color = imagecolorallocate($imageObj,200,200,200);
$line_color = imagecolorallocate($imageObj,220,220,220);
/* border within the perimeter of the graph */
//bool imagefilledrectangle(image, int x1, int y1, int x2, int y2, int color)
imagefilledrectangle($imageObj,1,1,$img_width-2,$img_height-2,$border_color);
imagefilledrectangle($imageObj,$margins,$margins,$img_width-1-$margins,$img_height-1-$margins,$background_color);
/* max height of the graph */
$max_value = max($arr_value);
$ratio = $graph_height/$max_value;
/* draw horizontal lines inside the graph area */
$horizontal_lines = 20;
$horizontal_gap = $graph_height/$horizontal_lines;
for($i=1; $i<=$horizontal_lines; $i++){
$y = $img_height – $margins – $horizontal_gap * $i;
//bool imageline(image, int x1, int y1, int x2, int y2, int color
imageline($imageObj,$margins,$y,$img_width-$margins,$y,$line_color);
$v = intval($horizontal_gap * $i/$ratio);
//bool imagestring(image, int font, int x, int y, int string, int color)
imagestring($imageObj,0,5,$y-5,$v,$bar_color);
}
/* Drawing the individual bar */
for($i=0; $i<$total_bars; $i++){
list($key,$value) = each($arr_value);
$x1 = $margins + $gap + $i * ($gap + $bar_width);
$x2 = $x1 + $bar_width;
$y1 = $margins + $graph_height – intval($value * $ratio);
$y2 = $img_height – $margins;
imagefilledrectangle($imageObj,$x1,$y1,$x2,$y2,$bar_color);
imagestring($imageObj,0,$x1 + 5,$y1 – 10, $value, $bar_color);
imagestring($imageObj,0,$x1 + 3,$img_height – 15,$key,$bar_color);
}
header(“Content-type:image/png”);
imagepng($imageObj);
Output of the above PHP script.

Bar Graph