tmyonline Posted March 19, 2008 Share Posted March 19, 2008 Hi guys: I need to display the result of a survey graphically (in a bar chart or pie chart). Are there PHP graphic functions that I can use ? I did some Google search but didn't find anything useful. Thanks. Link to comment https://forums.phpfreaks.com/topic/96976-php-graphic-display/ Share on other sites More sharing options...
BlueSkyIS Posted March 19, 2008 Share Posted March 19, 2008 learn to love (or hate) GD: http://us2.php.net/gd Link to comment https://forums.phpfreaks.com/topic/96976-php-graphic-display/#findComment-496249 Share on other sites More sharing options...
tmyonline Posted March 19, 2008 Author Share Posted March 19, 2008 Hi, Do I need to download a GD library in order to use the PHP / GD graphic functions ? Thanks. Link to comment https://forums.phpfreaks.com/topic/96976-php-graphic-display/#findComment-496269 Share on other sites More sharing options...
Barand Posted March 19, 2008 Share Posted March 19, 2008 You need php_gd2.dll in your extension folder, and make sure this line in php.ini is uncommented (ie no ; at start) extension=php_gd2.dll (if linux, it's a .so file instead of .dll) Here's a simple way to do a bar chart :: bar.php :: <?php // set dimensions $w = 102; $h = 20; // create image $im = imagecreate($w, $h); // set colours to be used $bg = imagecolorallocate($im, 0xE0, 0xE0, 0xE0); $black = imagecolorallocate($im, 0x00, 0x00, 0x00); $red = imagecolorallocate($im, 0xFF, 0x00, 0x00); $green = imagecolorallocate($im, 0x50, 0xB6, 0x30); // draw border imagerectangle($im, 0,0,$w-1,$h-1,$black); // get value and max value from query string $val = isset($_GET['val']) ? $_GET['val'] : 0; $max = isset($_GET['max']) ? $_GET['max'] : 100; // calculate dimensions of inner bar $barw = $max ? floor(($w-2) * $val / $max) : 0; $barh = $h - 2; // draw inner bar if ($barw) { $barcolor = $val < 50 ? $red : $green; imagefilledrectangle($im, 1, 1, $barw, $barh, $barcolor); } // send image header header("content-type: image/png"); // send png image imagepng($im); imagedestroy($im); ?> To use it <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN"> <html> <head> <META http-equiv="Content-Type" content="text/html; charset=iso-8859-1"> <META http-equiv="content-language" content="en"> <META name="author" content="Barand"> <META name="generator" content="PHPEd 4.5"> <title>Bar sample</title> </head> <body> <table width="300" border='0'> <tr> <td> Item A </td> <td> 20% </td> <td> <img src='bar.php?val=20&max=100'> </td> </tr> <tr> <td> Item B </td> <td> 40% </td> <td> <img src='bar.php?val=40&max=100'> </td> </tr> <tr> <td> Item C </td> <td> 30% </td> <td> <img src='bar.php?val=30&max=100'> </td> </tr> <tr> <td> Item D </td> <td> 60% </td> <td> <img src='bar.php?val=60&max=100'> </td> </tr> </table> </body> </html> Link to comment https://forums.phpfreaks.com/topic/96976-php-graphic-display/#findComment-496277 Share on other sites More sharing options...
PFMaBiSmAd Posted March 19, 2008 Share Posted March 19, 2008 Once you get or have the GD functions working, check out jpgraph - http://www.aditus.nu/jpgraph/ Link to comment https://forums.phpfreaks.com/topic/96976-php-graphic-display/#findComment-496379 Share on other sites More sharing options...
Barand Posted March 19, 2008 Share Posted March 19, 2008 or baaChart - see my sig Link to comment https://forums.phpfreaks.com/topic/96976-php-graphic-display/#findComment-496397 Share on other sites More sharing options...
Naez Posted March 19, 2008 Share Posted March 19, 2008 Barand for some reason the links in your sig don't point anywhere. Link to comment https://forums.phpfreaks.com/topic/96976-php-graphic-display/#findComment-496402 Share on other sites More sharing options...
Barand Posted March 19, 2008 Share Posted March 19, 2008 Some lowlife hacjed the site and changed them so I removed their links. Restored now. Thanks for the reminder. Link to comment https://forums.phpfreaks.com/topic/96976-php-graphic-display/#findComment-496405 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.