websoftexpert Posted June 25, 2008 Share Posted June 25, 2008 Hi I wish to create histogram Chart from database table. There are 13 column in table Column 1 = 8 Column 2 = 5 Column 3 = 8 Column 4 = 5 Column 5 = 8 Column 6 = 6 Column 7 = 7 Column 8 = 8 Column 9 = 9 Column 10 = 8 Column 11 = 12 Column 13 = 4 Column 13 = 2 I wish to create histogram Chart as shown in attached file I am using PHP4, But I also work in PHP 5 also. thanks in advance A sinha [attachment deleted by admin] Quote Link to comment Share on other sites More sharing options...
ober Posted June 25, 2008 Share Posted June 25, 2008 Check out http://code.google.com/apis/chart/ Quote Link to comment Share on other sites More sharing options...
websoftexpert Posted June 25, 2008 Author Share Posted June 25, 2008 Hi I am new to PHP Chart. I need something tutotrial like help or probabely code sample. I got no. of sample on this forum but didn't work. plz let me know if u can help me. thanks A SINHA Quote Link to comment Share on other sites More sharing options...
ober Posted June 25, 2008 Share Posted June 25, 2008 Did you even read the link I suggested? It's one giant help file on how to use it. I'd forget using the PHP Charting options if you can use Google Charts. Quote Link to comment Share on other sites More sharing options...
websoftexpert Posted June 25, 2008 Author Share Posted June 25, 2008 Hi thx for the link. Initially I read I thought It was bit difficult to undersatnd but now I think It is not after getting few things and example. thanks again A SINHA Quote Link to comment Share on other sites More sharing options...
Barand Posted June 25, 2008 Share Posted June 25, 2008 here's a very simple one (horizontal bars) :: bar.php :: <?php // set dimensions $w = 202; $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,$bg); // border uses background colur also imagecolortransparent($im, $bg); // now make bg colour transparent // 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 = $red; imagefilledrectangle($im, 1, 1, $barw, $barh, $barcolor); } // send image header header("content-type: image/png"); // send png image imagepng($im); imagedestroy($im); ?> sample <?php $data = array ( 'Column 1' => 8, 'Column 2' => 5, 'Column 3' => 8, 'Column 4' => 5, 'Column 5' => 8, 'Column 6' => 6, 'Column 7' => 7, 'Column 8' => 8, 'Column 9' => 9, 'Column 10' => 8, 'Column 11' => 12, 'Column 12' => 4, 'Column 13' => 2 ); $max = max($data); echo '<table>'; foreach ($data as $k=>$v) { echo "<tr><td>$k</td><td><img src='bar.php?max=$max&val=$v'> $v</td></tr>"; } echo '</table>'; ?> Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.