phpChart is easy to setup. In conf.php, simply set the value for SCRIPTPATH representing the relative or absolute URL to phpChart library.
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.
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: