Faqts : Computers : Programming : Shopping For You : PHP : Common Problems : Images

+ Search
Add Entry AlertManage Folder Edit Entry Add page to http://del.icio.us/
Did You Find This Entry Useful?

23 of 80 people (29%) answered Yes
Recently 1 of 10 people (10%) answered Yes


How do I make an line graph from the information returned by a query?

Dec 24th, 2001 04:26
Pekka Saarinen, A Ottenheimer, Matt Gregory, adrian Merrill, http://www.jeo.net/php/phplot/

You first need to get the (a) graphics library and build it in or 
include it as an extension of PHP.  After doing this you need to 
investigate and code a small function or script which can interpret the 
There are some sources that can help: http://www.jeo.net/php/phplot/
Some pseudo-code which might help:
  1.) set up the parameters for your graph such as x & y max values and 
height and width attributes.
  2.) retrive the data and analize it, (You need to decide how to do 
this for yourself based on what you are displaying.
  3.) Use the functions in the GD library or any other of your choosing 
(most other than GD will require you to add PHP extensions) to draw out 
your graph.
  4.) Make sure your return a content type of image/gif.
  5.) call the function/script from within an image tag.
This should work for you, but the solution can be as simple or as 
complicated as your needs dictate.
Check out this example!: 
(by P. Saarinen:)
Easier and faster way: map x's or y's to image tag's widths and 
heights. Use 1x1 color gif as image source.
// $width is INT returned from database
print "<img src=\"graphs/bar.gif\" width=\"";
print intval($width/10);
print "\" height=\"12\" alt=\"\" border=\"0\" vspace=\"0\" 
Add some code to check max width in page and scale down more if needed.