How to create bar graphs using complex queries from database dynamically

smartivn
09:01:10
Hello
I am trying to create a bar graph based on the values fetched from database. But the values fetched from database are coming from different tables and minor calculations performed on some of them before plotting a bar graph.

I have written the logic for fetching values and performing calculations in a file known as studenthelp.php. This file contains a link which opens up to another file containing the graph, known as studentgraph.php. And I now want to create a bar graph based on the values retrieved.

For now I have hard coded the values, and a bar graph does come. But I have no idea so as to how to fetch values that I have retrieved in studenthelp.php into this graph file for the graph to be displayed accordingly.

Since I am a novice in PHP I have no idea how to do this. Any suggestions would be appreciated.

Thanks.
smo1234
09-01-2010
You can use GD function of PHP to draw bar graph

You can check this how to create line graph by using data from MySQL table

However a bar graph can be drawn by using image function also by changing height value based on the data. Use one squre image of 3 or 4 pixcel. Then display it like this .

echo "<img src=dot.gif width=3 height=$height>";


Now if you pass the MySQL data to this $height variable then you will have vertical bars representing data of the table.
Please Login to post your reply or start a new topic