Q:

Bar images issue on graph using GD libraray

I just want to know how to display bars with exact data array value on my graph using Gd library functions with for loop / for-each loop kindly reply me  
helps are definitely appreciated 
Confusion comment tag in this code is indicate my problem
$array = array(
              "Jan" => 110,
              "Feb" => 130,
              "Mar" => 215,
              "Apr" => 81,
              "May" => 310,
              "Jun" => 110,
              "Jul" => 190,
              "Aug" => 175,
              "Sep" => 850,
              "Oct" => 286,
              "Nov" => 150,
              "Dec" => 196);

$width = 600;
$height = 500;
$margin = 20;
$line_width  = $width-($margin*4)-25-15;
$line_height = $width-$margin;

$max_array_value=max($array);
$min_array_value=min($array);

$im = imagecreate($width,$height);

$red = imagecolorallocate($im,225,0,0);
$black = imagecolorallocate($im,0,0,0);
$white  = imagecolorallocate($im, 255, 255, 255);

// Create rectangle with margin color borders 
imagefilledrectangle($im,$margin,$margin,$width-$margin,$height-$margin,$black);

// Create vertical line
for($i=25;$i<=$line_width;$i+=15){
    imageline($im,$margin,$i,$width-$margin,$i,$white);
}

// Create horizontal line
for($i=25;$i<=$line_height;$i+=15){
    imageline($im,$i,$height-$margin,$i,$margin,$white);
}

$j=480;
for($i=$min_array_value;$i<=$max_array_value;$i+=$min_array_value){
    imagestring($im,3,1,$j-=20,$i,$white);
}

//for Start Confusion here
imagefilledrectangle($im,45 ,400,$width-565,$height-20,$red);
imagefilledrectangle($im,60 ,300,$width-550,$height-20,$red);
//for End Confusion here     

header("Content-type:image/jpeg");
imagepng($im);

 

A:

You need to loop over your array creating bars using the data.  My code is not exact, you will have to adjust the parameters until the bars come out the way you want.  Try replacing your confusing section with something like this:
$n = 0;
foreach($array as $k => $v) {
    imagefilledrectangle($im, ($n * 15) + 45, 400, ($n * 15 + 55), 400 - $v, $red);
    $n++;
}

