pie chart

2D/3D Pie Chart for PHP

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

2D/3D Pie Chart for PHP

Tutorials - Data direct from MySQL Databases

Before following this tutorial it is essential that the graph software has been installed. If you have not yet done so then you should complete the install procedure now,
Quick Set-Up and Install »

This tutorial demonstrates how to set the graph to dynamically pull the data directly from MySQL databases.

Step 1 - Add the <IMG> tag to your web page

Add this HTML code to your page
(replacing yourdomain.com with the actual domain of your web site and [URL FilePath] with the url of the web directory where your page resides),

<img src="http://www.yourdomain.com/jpowered/piechart/pie-chart.php?
dbinfo=[URL FilePath]/dbinfo.txt&
config=[URL FilePath]/config.txt"
width=300
height=300>

Save the web page and load it up to your web server.

 

Step 2 - Create a MySQL Database

For the purpose of this tutorial the following MySQL database should be created.-

CREATE DATABASE graphtestdb;

USE graphtestdb

CREATE TABLE sales
(month INT PRIMARY KEY,
productx REAL,
producty REAL,
productz REAL);

 

Now add the following data to the 'sales' table:-

INSERT INTO sales VALUES( 1,345,100,800);

INSERT INTO sales VALUES( 2,445,200,740);

INSERT INTO sales VALUES( 3,945,300,680);

INSERT INTO sales VALUES( 4,1145,400,697);

INSERT INTO sales VALUES( 5,780,500,524);

INSERT INTO sales VALUES( 6,640,600,100);

 

 

 

Notes:

If you would prefer to use one of your existing MySQL databases (rather than create this new one) then simply add the sales table to that database.

If you do use one of your own databases then ensure that you change the database name in the dbinfo.txt file - see next step.

Step 3 - Edit the dbinfo.txt file

In order for the graph to connect to the database it requires certain pieces of information including a database username and password.

In the /tutorials/ directory (of this package) you will find a file "dbinfo.txt" which contains the following:-

server: localhost
username: [USER]
password: [PASSWORD]
database: graphtestdb

SELECT productx FROM sales ORDER BY month

SELECT producty FROM sales ORDER BY month

 

Edit this file replacing [USER] and [PASSWORD] with a valid logon for your MySQL database.

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

Load the modified file up to your web server placing it in the same directory as your web page from step 1.

 

 

Notes:

A server value of "localhost" is usually sufficient where the database resides on the same server as the web server. However if your database system is operating on another server then change the "localhost" value to the name (or IP) or that server.

The graphing software will execute each of the SELECT statements found in this file. The results of each query will be plotted as a series of data on the chart.

Step 4 - Create the config file

From the /tutorials/ directory (of this package) copy the files config.txt to your web server.

This file should be placed in the same directory as your web page.

 

 

Notes:

This config.txt file contains the parameters which determine certain aspects of the graph like colors and fonts. For the function and options of each parameter see the following page:-

Graph Parameters »

Final Step - View the page in a browser

Open your web browser and view the page.

You should see two Pie Charts each with 6 segments.

 

 

Follow-Up Suggestion:

Create another dbinfo file which connects to one of your databases and pulls data from one of the tables.

 

Security Warning

The dbinfo.txt contains your database logon details. In this tutorial this information has been placed within a web directory which can be read by anyone who is able to access your site.

For a real implementation, it is highly recommend that you place dbinfo files outside of your web directories (ie. outside the /public_html/ directory). The <IMG> tag should then be modified to provide the file path to the file, eg.

<img src="http://www.yourdomain.com/jpowered/piechart/pie-chart.php?
dbinfo=../../dbinfo.txt&
config=config.txt"
width=300
height=300>

( the correct syntax for the file path may vary from file system to file system ).

When to use this type of implementation.

If the data to be plotted resides in a MySQL database then this method is both very efficient and automatically provides real-time graph capability.

 

 

« back to Getting Started next Tutorial »

Any Problems ?

In the vast majority of cases (over 95%) the above is all that is required. However if you experience any problems please feel free to tell us and we will be happy to assist.

Contact us here »

Please remember to include the URL of your web page.

[ 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 »