Click here to Skip to main content
15,561,246 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hello..
I want to draw a graph from the values i have in my table in database..
E.g, i have a table age in my database.. I have a form in html where i will display the graph.. I want to get a graph displaying the different age i have in my table..
Can you help me..
thank uu..
Posted

1 solution

There could be many different ways. Basically, you can generate any graphics out of your data on the server side, save it in a temporary file, or provide graphics content on the fly prescribing proper media type in your HTTP response. With PHP, it can be anything. It could be something like "image/png", "image/jpeg", etc. Please see:
http://en.wikipedia.org/wiki/Media_type[^],
http://www.php.net/manual/en/function.header.php[^],
the ultimate document on available MIME types is this one (for images): http://www.iana.org/assignments/media-types/media-types.xhtml#image[^].

So, in your PHP script, it could be something like
PHP
header('Content-type: image/png');
/* or */
header('Content-type: image/jpeg');


For generation of general graphics, there are many libraries (like ImageMagick, http://www.php.net/manual/en/book.imagick.php[^]).

This is how it works. In practice, you can find some read-to-use open-source charting library: http://bit.ly/OCsZbx[^].

There is a very attractive alternative approach: using HTML5 Canvas feature: http://en.wikipedia.org/wiki/HTML5_Canvas[^].

For example, this product: http://canvasjs.com[^].

You can find more: http://bit.ly/OCww9S[^].

If you use this approach, your PHP code should be used to generate data and Javascript needed to present graphics. The attractiveness of this approach is that you can make graphics (especially changing view options, limits, etc.) on the fly with great performance, because all such processing can be done purely on client side.

—SA
 
Share this answer
 
v2
Comments
Maciej Los 19-Mar-14 17:18pm    
+5!
Sergey Alexandrovich Kryukov 19-Mar-14 17:34pm    
Thank you, Maciej.
—SA

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900