Re: draw graph

From: Date: Wed, 25 Jul 2001 14:06:17 +0000
Subject: Re: draw graph
References: 1  Groups: php.db 
Request: Send a blank email to php-db+get-10750@lists.php.net to get a copy of this message
"Sommai Fongnamthip" <sommai@thaithanakit.co.th> wrote in message news:5.1.0.14.2.20010725153241.00a8dc20@langsuan.thaithanakit.co.th... > 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; }

« previous php.db (#10750) next »