pie chart

2D/3D Pie Chart for PHP

[ Pie Chart Home ] [ Set-Up ] [ Tutorials ] [ Documentation ] [ Buy Now ] [ Support ]

2D/3D Pie Chart for PHP

Documentation - Adding data to a graph

Data may be added to the graph in one of four ways:-

Retrieving Data from files »

Retrieving Data from another server process »

Retrieving Data from a MySQL Database »

A PHP Data Script »

 

Retrieving Data from files

To set the graph to read the data from file simply add the "data" parameter to the URL string of the <IMG> tag. For example if the data file is "graphdata.txt" then your <IMG> tag would become:-

<img src="pie-chart.php?data=graphdata.txt"
width=500 height=500>

 

Data Format

Within the file the data should follow this format:-

dataNseriesM: [value]

where N represents the position of the data item in the series and M represents the series (Pie) number.

For example for 3 series of data each containing 6 points the contents of the data file would be:-

data1series1: 30
data2series1: 20
data3series1: -10
data4series1: 40
data5series1: 50
data6series1: 60

data4series2: 40
data5series2: 50
data6series2: 60

data1series3: 100
data2series3: 50
data3series3: -25
data4series3: 75
data5series3: 125
data6series3: 150

 

«back to top

 

Retrieving Data from another server process

To set the graph to read the data from another server side process (ie. PHP, ASP, JSP etc) simply add the "data" parameter to the URL string of the <IMG> tag.
For example if the data script is "graphdata.php" then your <IMG> tag would become:-

<img src="pie-chart.php?data=graphdata.php"
width=500 height=500>

 

Data Format

The data script should be written such that it outputs the data in the following format:-

dataNseriesM: [value]

where N represents the position of the data item in the series and M represents the series (pie) number.

For example for 3 series of data each containing 6 points the output of the data script would be:-

data1series1: 30
data2series1: 20
data3series1: -10
data4series1: 40
data5series1: 50
data6series1: 60

data4series2: 40
data5series2: 50
data6series2: 60

data1series3: 100
data2series3: 50
data3series3: -25
data4series3: 75
data5series3: 125
data6series3: 150

«back to top

Retrieving Data from a MySQL Database

The graph can be set to connect to and retieve data directly from a MySQL database. In order to do this the graphing software requires some information about the database. This information should be placed in a file which can be read by the graphing software. The filename should then be specified in the URL string of the <IMG> tag with the parameter "dbinfo"

For example, if the file containing the db information is "dbinfo.txt" then the <IMG> would be:-

<img src="pie-chart.php?dbinfo=dbinfo.txt"
width=500 height=500>

The dbinfo file will need to contain the following information:-

server:
username:
password:
database:

a SELECT statement for each series of data.

For example, if a MySQL db named "Sales" has a username of "salesaccess" and a password of "dbpass" with 3 tables "product1", "product2" and "product3" then the dbinfo contents would be:-

server: localhost
username: salesaccess
password: dbpass
database: Sales

SELECT priceUSD FROM product1
SELECT priceUSD FROM product2
SELECT priceUSD FROM product3

Please note: Do NOT add the semi-colon character to the end of the SELECT statements.

 

«back to top

A PHP Data Script

This feature allows you to create your own custom PHP Data Script function. The function will be included at run time and used by the graph to acquire the data.

This method provides enormous flexibility for the data acquisition process. In addition any SESSION data (such as a user ID) that exists will also be available to this data script.

A custom data script is specified via the parameter "datascript". For example if your data script is in a file datascript.php which resides in the same directory as the graph function then your <IMG> tag would be:-

<img src="area-graph.php?datascript=datascript.php"
width=500 height=500>

The data script must be valid PHP code and should contain at least the following function:-

function datascript() {

 

return $lines;

}

where $lines is a string array containing the data parameters and values.

The contents of the string array should be the format:-

dataNseriesM: [value]

where N represents the position of the data item in the series and M represents the series number.

For example, for 3 series of data each containing 6 points the string array contain:-

data1series1: 30
data2series1: 20
data3series1: -10
data4series1: 40
data5series1: 50
data6series1: 60

data4series2: 40
data5series2: 50
data6series2: 60

data1series3: 100
data2series3: 50
data3series3: -25
data4series3: 75
data5series3: 125
data6series3: 150

 

Note: The data script should under no circumstances write out any information via the print or echo functions. This would cause the production of the graph image to fail.

 

For an example datascript.php and further guidance on how to use this method please see the Tutorial section »

 

 

«back to top

 

« back to Getting Started
[ Pie Chart Home ] [ Set-Up ] [ Tutorials ] [ Documentation ] [ Buy Now ] [ Support ]

How it Works »

How the graphing software works.

Quick Set-Up and Install »

step-by- step guide to add graphing for your site.

Tutorials »

Introducing many powerful features.

Licensing and Purchase Options »

Click the 'Buy & Download' button to review options.

buy and download pie chart graph for php

Documentation »

Full documentation

Help and Support »

If at any stage you require help or advice then please feel free to ask.

Contact us here »