This is my code that I am currently using:
<?PHP
header("HTTP/1.1 200 OK");
header("Content-type: image/jpeg");
// generates bar graph
include ("odbclib.inc");
include ("genlib.inc");
include ("dateslib.inc");
include ("graphslib.inc");
// globals taken from URL
global $graph_url;
global $realstartdate;
global $realenddate;
global $vmargin;
global $hmargin;
global $height;
global $width;
// other globals used
global $results;
global $results1;
$startdate = "";
$enddate = "";
// values used for drawing graph
convert_date_to_string($realstartdate,&$startdate);
convert_date_to_string($realenddate,&$enddate);
open_db();
query_db("SELECT duration+dial_duration+authen_duration,start_time FROM load_test_run_results WHERE error_code = '200' AND url = '$graph_url' AND (start_time >= #$startdate# AND start_time <= #$enddate#) ;");
get_query_results2();
close_db();
// get these to use in graph
$nval = sizeof($results);
$maxval = max($results);
// echo $maxval . "<BR>\n";
round_up($maxval,&$maxval);
// echo $maxval . "<BR>\n";
// create image image handle
$jpeg_im = ImageCreate($width,$height);
// colors
$white = imagecolorallocate($jpeg_im,0xFF,0xFF,0xFF);
$black = imagecolorallocate($jpeg_im,0x00,0x00,0x00);
$navy = imagecolorallocate($jpeg_im,0x00,0x00,0x80);
$gray = imagecolorallocate($jpeg_im,0xC0,0xC0,0xC0);
// draw border round graph
$base = floor(($width - $hmargin)/$nval); // distance between columns
$ysize = $height - 2 $vmargin; // y-axis plot
$xsize = $nval $base; // x-axis plot
ImageFilledRectangle($jpeg_im,0,0,$height,$width,$white);
imagerectangle($jpeg_im, $hmargin, $vmargin, $hmargin+$xsize, $vmargin+$ysize, $black);
// draw title
$titlefont = 3;
$title = $graph_url;
$txtsz = imagefontwidth($titlefont) * strlen($title);
$xpos = (int)($hmargin + ($xsize - $txtsz)/2);
$xpos = max(1,$xpos);
$ypos = 3;
imagestring($jpeg_im,$titlefont,$xpos,$ypos,$title,$black);
// y labels and grid lines
$labelfont = 2;
$ngrid = 8; // number of grid lines
$dydat = $maxval/$ngrid; // data units between grid lines
$dypix = $ysize/($ngrid + 1); // pixels between grid lines
for($i = 0; $i <= ($ngrid + 1);$i++) {
// iterate over y ticks
$ydat = (int)($i $dydat); // height of grid line in units of data
$ypos = $vmargin + $ysize - (int)($i$dypix); // height of grid line in pixels
$txtsz = imagefontwidth($labelfont) * strlen($ydat); // pixel width of label
$txtht = imagefontheight($labelfont); // pixel-height of label
$xpos = (int)(($hmargin - $txtsz)/2);
$xpos = max(1,$xpos);
imagestring($jpeg_im,$labelfont, $xpos, $ypos - (int)($txtht/2),$ydat,$black);
if (!($i == 0) && !($i > $ngrid))
imageline($jpeg_im,$hmargin - 3, $ypos, $hmargin + $xsize, $ypos, $gray);
}
// columns and x labels
$padding = 3; // half of spacing between columns
$yscale = $ysize / (($ngrid+1)*$dydat); // pixels per data unit
$xpix = ($realenddate - $realstartdate)/($width-$hmargin);
for ($i = 0; list($xval,$yval) = each($results); $i++) {
// vertical columns
$expl = explode(" ",$results1[$i]);
$temp = explode("-",$expl[0]);
$temp1 = explode(":",$expl[1]);
$currentdate = mktime($temp1[0],$temp1[1],$temp1[2],$temp[1],$temp[2],$temp[0]);
$xcurpos = ($currentdate - $realstartdate)/$xpix;
$ymax = $vmargin + $ysize;
$ymin = $ymax - (int)($yval*$yscale);
$xmax = $hmargin + $xcurpos+10;
$xmin = $hmargin + $xcurpos;
imagefilledrectangle($jpeg_im,$xmin,$ymin,$xmax,$ymax,$navy);
}
// x-axis labels
$nxlabels = 3;
$xdatinc = ($realenddate - $realstartdate)/$nxlabels;
$currentdate = $realstartdate;
$xdat = "";
for ($i=0; $i <= ($nxlabels + 1); $i++) {
$currentdate = $currentdate + $xdatinc;
$xcurpos = ($currentdate - $realstartdate)/$xpix;
convert_date_to_string1($currentdate,&$xdat);
$temp = explode(" ",$xdat); // split date/time up ready for printing on x-axis
// time
$txtsz = imagefontwidth($labelfont) * strlen($temp[0]);
$txtht = imagefontheight($labelfont);
imagestring($jpeg_im,$labelfont,($xcurpos - ($txtsz/2)),($ymax+6),$temp[0],$black);
// date
$txtsz = imagefontwidth($labelfont) * strlen($temp[1]);
$txtht = imagefontheight($labelfont);
imagestring($jpeg_im,$labelfont,($xcurpos - ($txtsz/2)),($ymax+6+$txtht),$temp[1],$black);
imageline($jpeg_im,$xcurpos,$ymax,$xcurpos,$ymax+3,$black);
}
// flush image
imagejpeg($jpeg_im,"devim.jpg");
imagedestroy($jpeg_im);
?>