Plotting data from a MySQL database using jpgraph

First Step: Putting the jpgraph library on the server

The jpgraph library can be downloaded from here. After it is downloaded put it somewhere on the server or local computer you are using it on. It doesn’t matter where you put it exactly. I put it in public_html/jpgraph on my server. There are loads of examples provided with the library. So you can check if everything is working by pointing your browser to one of the example files. You can check out one of the examples by going to this link : http://www.wattnotions.com/jpgraph/src/Examples/centeredlineex01.php.

Grab data from a MySQL DB and plot it.

Using the example graph linked above it was very simple to add in some code to connect to a mysql database and store some numbers in an array. This array is then passed to jpgraph and it plots it. If only one set of numbers (in this case the y-axis) is passed, then jpgraph will automatically make the x-axis starting from 0 and incrementing by 1 for each y point.

The numbers in the MySQL database were randomly generated by a python script. The PhP script to retrieve these numbers and plot them is shown below: