Entry
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
data.
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!:
http://kes.tscnet.com/monitor/lines/current.php3
---------------------------
(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\"
align=\"middle\">";
?>
Add some code to check max width in page and scale down more if needed.