phpChart is easy to setup. It does NOT required GD or any other third party, server-side graph library or extension. In conf.php, simply set the value for SCRIPTPATH representing the relative or absolute URL to phpChart library.
1 | define('SCRIPTPATH','/phpChart/'); // /phpChart/ is the absolute path to the phpChart files assuming phpChart folder is a folder in the web root. |
That’s it. You are done with the setup.
Now, let’s start coding. First of all, include conf.php in on top of the every page that uses phpChart.
1 | require_once("../conf.php"); // this must be include in every page that uses phpChart. |
Once it is included, you will need only two lines of code to have a working PHP Chart as the example shown below. All phpChart code will require those two lines that take a series of data and an unique name. Data is passed in as an array of series that is either an array of y values or an array of paired [x,y]. No additional plugins or options are required.
- The first line is to create our phpChart object by calling the constructor with two parameters;
- the 1st parameter is the data, which must be an array of y values or array of paired [x, y]
- The 2nd parameter is the unique name for the chart. The unique name cannot have letter space.
- The second line is the draw function to render the chart.
The complete code:
Note that ALWAYS to include <!DOCTYPE HTML> before <html> tag , so that HTML5 elements such as canvas are rendered in modern web browser.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 |
It’s impossible to demostrate every single property used in phpChart because there are simply too many. The quickest way to get started is to look at each examples on this page. Each examples comes with the PHP source code as well as generated client-side javascript, and the chart. phpChart is built on top of jqPlot javascript charting library. For complete reference, visit http://www.jqplot.com/docs/files/jqplot-core-js.html