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.
Link to comment
Share on other sites

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.
Link to comment
Share on other sites

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.
Link to comment
Share on other sites

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?
Link to comment
Share on other sites

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?
Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.