Showing posts with label PHP. Show all posts
Showing posts with label PHP. Show all posts
RGraph - Creating a bar chart using PHP
Here we go, Creating charts using data from MySql using PHP. The charting plugin we going to use rgraph which is an open source and you can download it from here. The rgraph libraries are written wih javascrit and it has made it easy like we just need to populate the values and we get the graph for the data.
Creating a bar graph:
Before we draw the graph we need to create a database and a table in MySQL. You can follow the steps here. Lets get into the important stuff now,
below is the PHP code for the Bar Chart.
Similarly we can create different charts like line, pie, horizontal, etc. These charts proerties can be changed and we can make it even more better. It will appear in default variant if properties not changed.
Different Rgraphs available are,
Creating a bar graph:
Before we draw the graph we need to create a database and a table in MySQL. You can follow the steps here. Lets get into the important stuff now,
- After creating the table, create a new folder in htdocs folder give any name without space.
- Move the libraries folder from the rgraph zip file which you have downloaded from the above link.
- Create a PHP file in the same folder and copy paste the below code.
below is the PHP code for the Bar Chart.
Similarly we can create different charts like line, pie, horizontal, etc. These charts proerties can be changed and we can make it even more better. It will appear in default variant if properties not changed.
Different Rgraphs available are,
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
How to work on phpMyAdmin
phpMyAdmin is a free software tool for handling the administration of MySQL over the web. This gives a user friendly environment to Create and manage database and data. The Xampp which we discussed earlier also includes phpMyAdmin. So if you have installed xampp phpMyAdmin is already installed.
Creating a Database:
To insert data:
Not installed Xampp??? Click here. or you can also install it seperately but you will need to install Apache server for running the PHP files. So best way is Xampp.
Creating a Database:
- Start Xampp server.
- Type http://localhost/phpmyadmin in the browser and press Enter.
- Click on `Databases` tab.
- Type any name for the database and click Create button.
That's it your database is created.
Creating a table:
- All the databases will be listed on the left side pane. Click on the database you created.
- Give the table name in the text box and enter number of columns(This can be modified later).
- Click Go.
- Now Enter the Column Name and other attributes that are required like length and Type. (there will be option to add more columns here at the top)
- Click Go, your table is created.
Below screen image shows you the phpMyAdmin after creating table. Here daily_statistics is the table name and database name is test.
![]() |
| Marked database and table names |
To insert data:
- Click on the table name.
- Click the `Insert` tab.
- Enter values in the respective columns and click Go.
- By clicking on the `Browse` tab you can view the inserted values.
How to run a php file
A php script is usually used to build websites and is interpreted by a web server. So you need to install a server like Apache and also PHP. As a beginner it is better to install Xampp server because if you install each separately you also need to configure the files accordingly. So it's better to install Xampp Server, you can install by following the steps here.
Create a sample php file to check whether the xampp works. Type the below code in a tex editor and save it as "first.php" in /opt/lampp/htdocs/ .
Create a sample php file to check whether the xampp works. Type the below code in a tex editor and save it as "first.php" in /opt/lampp/htdocs/ .
"My first PHP script!". That's all you PHP file is working, now start coding ;)
Subscribe to:
Comments (Atom)

