Jump to content

** Fixed ** Horizontal Bar Graph based off DB Numbers Logic Questions...


thepip3r

Recommended Posts

if I have a value that I'm pulling out of a database, I'm just wondering how you'd generate a horizontal bar efficiently.  The only way I can think to do it is to echo out x amount of <img> tags calling slivers of an image.  That's a whole lot of img tags and just wanted to see if there was a better way of doing it or not??

edit:  cursory searches on google only yield 2d/3d bar graph software that you pay for.
Thanx Barand.  I haven't given it a shot yet but NOT stringing together X amount of <img> tags is what I was looking for and it looks like PHP has a function that will generate a graph off your link with just a min/max val; thanx as always.
Well I figured out my Header errors and now I don't get any errors.. I just get gibberish.  I'm using the exact code (almost) from the link you posted Barand but my output is the following:

[quote]‰PNG  IHDR, ¥Èhd PLTEàààÿÿ™"ÂIDATxœc¥`p` `5kÔ¬!có Ñ4Y®S…¿IEND®B`‚ [/quote]

[code=php:0]// set dimensions
    $w = 300;
    $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, 0xFF, 0x00);
// draw border
    imagerectangle($im, 0,0,$w-1,$h-1,$black);
// get value and max value from query string
    $val = 0;
    $max = 100;
// 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);[/code]

as you can see, i changed the $val and $max from $_GET vars to fixed values so I can test out how it looks and stuff.  can you recommend any help??  i also had to enable the gd2 extension in my php.ini.
this might have to do with the fact that I haven't downloaded GD-2.  I just downloaded the .zip for my windows server but where do I put the extracted folder and how do i tell PHP to use the contents??? the man page for GD doesn't say... just says to enable the extension.
Search php.ini for the "extension_dir" setting and put "php_gd2.dll" in there.

Mine is
extension_dir="./"

which is "C:/PHP" - default

PS and try placing it on the page using an html img tag as described in the link I posted
well i know my extension dir is good because i've enabled LDAP support so i can query AD and that works fine and i accomplished it by just uncommenting the ldap extension in php.ini.  i guess my question was more of that I downloaded gd-2.0.33 from http://www.boutell.com/gd/ and i was wondering if there's anything i have to do with that zip file or is PHP's extension already perform all of the functionality of that GD library without all the source files??  More basically, is there anything I should have to do to endable GD support other than uncommenting the extension in my php.ini?
hmm.. i apologize for not trying that before Barand... i didn't quite understand what you meant by using an <img> tag until you posted that code; i wasn't aware you could reference a php page like that in an <img> tag.  regardless, it worked.  so i can pretty much just leave it like that right?  and just call bar.php and pass $_GET values to it ???  does that help explain why it wasn't showing up correctly with the other way i had it?

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.