"Sommai Fongnamthip" <[EMAIL PROTECTED]> wrote in message
[EMAIL PROTECTED]">news:[EMAIL PROTECTED]...
> Dear,
> How could I draw graph with gd by using PHP code with custom log scale?
How 'bout:
function drawLogGraph($arr) {
$xoffs = 20;
$yoffs = 180;
$drawwidth = 160;
$drawheight = -160;
$logscale = -10; // height of a 10x division
$logscalebase = 1; // '0' on your graph
$numbars = count($arr);
$perbar = $drawwidth / $numbars;
$barwidth = 0.8; // ... fractional draw width
$halfsp = (1 - $barwidth) * 0.5;
$img = ImageCreateFromPNG("graphbackground.png") or die("Could not load
background");
for ($i = 0; $i < $numbars; $i++) {
$barleft = $perbar * ($i + $halfsp);
$barright = $perbar * ($i + 1 - $halfsp);
$bartop = (log10($arr[$i]) - $logscalebase) * $logscale;
ImageFilledRectangle($img, $xoffs + $barleft, $yoffs + $bartop,
$xoffs + $barright, $yoffs, 1);
}
return $img;
}
--
PHP Database Mailing List (http://www.php.net/)
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
To contact the list administrators, e-mail: [EMAIL PROTECTED]