ali_2kool2002 Posted March 31, 2007 Share Posted March 31, 2007 Hi i am having a lot of problems trying to get software to create graphs using php/mysql could anyone suggest somewhere where i can easily create simple bar graphs? hope someone knows the answer, or even know how to code in php 2 enter a few details as a graph... :'( :'( Link to comment Share on other sites More sharing options...
Edward Posted March 31, 2007 Share Posted March 31, 2007 I can only offer you a pie. A pie chart, that is. Try http://www.peters1.dk/webtools/php/lagkage.php?sprog=en. If memory serves I may have had to play around with it a bit to get it right (aside from the obvious customisation) but I got it working perfectly almost immediately. Link to comment Share on other sites More sharing options...
Barand Posted March 31, 2007 Share Posted March 31, 2007 For a simple bar bar.php <?php // set dimensions $w = 102; $h = 12; // create image $im = imagecreate($w, $h); // set colours to be used $bg = imagecolorallocate($im, 0xE0, 0xE0, 0xE0); $black = imagecolorallocate($im, 0x00, 0x00, 0x00); $barcolor = imagecolorallocate($im, 0xFF, 0x00, 0x00); // draw border imagerectangle($im, 0,0,$w-1,$h-1,$black); // get value and max value from query string $val = $_GET['val']; $max = $_GET['max']; // calculate dimensions of inner bar $barw = $max ? floor(($w-2) * $val / $max) : 0; $barh = $h - 2; // draw inner bar if ($barw) imagefilledrectangle($im, 1, 1, $barw, $barh, $barcolor); // send image header header("content-type: image/png"); // send png image imagepng($im); imagedestroy($im); ?> To display <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="300px" border='1'> <tr> <td> Item A </td> <td> 20 </td> <td> <img src='bar.php?val=20&max=50'> </td> </tr> <tr> <td> Item B </td> <td> 40 </td> <td> <img src='bar.php?val=40&max=50'> </td> </tr> <tr> <td> Item C </td> <td> 30 </td> <td> <img src='bar.php?val=30&max=50'> </td> </tr> <tr> <td> Item D </td> <td> 50 </td> <td> <img src='bar.php?val=50&max=50'> </td> </tr> </table> </body> </html> Link to comment Share on other sites More sharing options...
ali_2kool2002 Posted March 31, 2007 Author Share Posted March 31, 2007 only displays the table and not the third coloum where the bar graph should be if i do the code above... Link to comment Share on other sites More sharing options...
ali_2kool2002 Posted March 31, 2007 Author Share Posted March 31, 2007 Do i need to install some extra software such as GD SOMETHING? Link to comment Share on other sites More sharing options...
Barand Posted March 31, 2007 Share Posted March 31, 2007 Yes you do need GD Check your php.ini file to see what your extension_dir is defined as ; Directory in which the loadable extensions (modules) reside. extension_dir = "./" and make sure php_gd2.dll ( or php_gd2.so if linux) is in there Then find this line and remove the ";" from the beginning: ;extension=php_gd2.dll Link to comment Share on other sites More sharing options...
ali_2kool2002 Posted March 31, 2007 Author Share Posted March 31, 2007 tried above no difference as i dont think the computer im using has gd installed? where can i install it from ,, is it str8 forward 2 install ? Link to comment Share on other sites More sharing options...
Barand Posted March 31, 2007 Share Posted March 31, 2007 You can download extensions from www.php.net Link to comment Share on other sites More sharing options...
ali_2kool2002 Posted March 31, 2007 Author Share Posted March 31, 2007 can i make graphs without GD?? as i really dont know how to configure it...sorry Link to comment Share on other sites More sharing options...
Barand Posted March 31, 2007 Share Posted March 31, 2007 As you have started another topic on configuring gd I'll close this one. Link to comment Share on other sites More sharing options...
Recommended Posts