thepip3r Posted November 3, 2006 Share Posted November 3, 2006 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. Quote Link to comment Share on other sites More sharing options...
Psycho Posted November 3, 2006 Share Posted November 3, 2006 How bout you just echo one image per data item with a width dependant upon the value for the data item. Give examples of your data if you need more info. Quote Link to comment Share on other sites More sharing options...
Barand Posted November 3, 2006 Share Posted November 3, 2006 Seehttp://www.phpfreaks.com/forums/index.php/topic,105508.msg422119.html#msg422119 Quote Link to comment Share on other sites More sharing options...
thepip3r Posted November 3, 2006 Author Share Posted November 3, 2006 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. Quote Link to comment Share on other sites More sharing options...
thepip3r Posted November 3, 2006 Author Share Posted November 3, 2006 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. Quote Link to comment Share on other sites More sharing options...
thepip3r Posted November 3, 2006 Author Share Posted November 3, 2006 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. Quote Link to comment Share on other sites More sharing options...
Barand Posted November 3, 2006 Share Posted November 3, 2006 Search php.ini for the "extension_dir" setting and put "php_gd2.dll" in there.Mine isextension_dir="./"which is "C:/PHP" - defaultPS and try placing it on the page using an html img tag as described in the link I posted Quote Link to comment Share on other sites More sharing options...
thepip3r Posted November 3, 2006 Author Share Posted November 3, 2006 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? Quote Link to comment Share on other sites More sharing options...
Barand Posted November 3, 2006 Share Posted November 3, 2006 Just make sure you have "php_gd2.dll" in your extensions folder Quote Link to comment Share on other sites More sharing options...
thepip3r Posted November 3, 2006 Author Share Posted November 3, 2006 go it.. file version 5.1.4.4 in c:\PHP\ext. and i'm getting that gibberish that i showed above. do you have any recommendations barand? i'm new to GD and am at a loss. =/ Quote Link to comment Share on other sites More sharing options...
Barand Posted November 3, 2006 Share Posted November 3, 2006 Did you try an IMG tag[code]<img src='bar.php?val=30&max=100'>[/code] Quote Link to comment Share on other sites More sharing options...
thepip3r Posted November 3, 2006 Author Share Posted November 3, 2006 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? Quote Link to comment Share on other sites More sharing options...
Barand Posted November 3, 2006 Share Posted November 3, 2006 Probably. Not sure how you were using the code.You should be able to run the script on its own and get the image (set val to > 0 or all you get is a rectangle) Quote Link to comment Share on other sites More sharing options...
thepip3r Posted November 3, 2006 Author Share Posted November 3, 2006 Thanx for the help Barand; I do appreciate it. Quote Link to comment Share on other sites More sharing options...
Barand Posted November 3, 2006 Share Posted November 3, 2006 You're welcome 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.