Happy Codings - Programming Code Examples
Html Css Web Design Sample Codes CPlusPlus Programming Sample Codes JavaScript Programming Sample Codes C Programming Sample Codes CSharp Programming Sample Codes Java Programming Sample Codes Php Programming Sample Codes Visual Basic Programming Sample Codes


Php Programming Code Examples

Php > Graphics Code Examples

Display a bar chart based on random values

Display a bar chart based on random values <? // bars.php3 - Bar chart on gif image // Note: uses the gd library // This code will display a bar chart based on random values // Different colors are used to display bars and a gif images // is used for the background. Use the following link to include // the example into your web-site // <img src="./bars.php3" border="0"> // // The background image can be found at Header( "Content-type: image/gif"); Header( "Expires: Mon, 17 Aug 1998 12:51:50 GMT"); $im = imagecreatefromgif( "gradient.gif"); // Allocate colors $red=ImageColorAllocate($im,255,0,0); $green=ImageColorAllocate($im,0,255,0); $blue=ImageColorAllocate($im,0,0,255); $yellow=ImageColorAllocate($im,255,255,0); $cyan=ImageColorAllocate($im,0,255,255); // Determine size of image $x=imagesx($im); $y=imagesy($im); // Initialize random number generator srand(mktime()); // Create some bars $v=rand(); $v=$v/32768*200; ImageFilledRectangle($im,10,200-$v,60,200,$red); $v=rand(); $v=$v/32768*200; ImageFilledRectangle($im,70,200-$v,120,200,$green); $v=rand(); $v=$v/32768*200; ImageFilledRectangle($im,130,200-$v,180,200,$blue); $v=rand(); $v=$v/32768*200; ImageFilledRectangle($im,190,200-$v,240,200,$yellow); $v=rand(); $v=$v/32768*200; ImageFilledRectangle($im,250,200-$v,300,200,$cyan); // Display modified image ImageGif($im); // Release allocated ressources ImageDestroy($im); ?>