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.
Javascript importanrt iMacros commands
I used JavaScript to have a controlled run of multiple macros. It's easy to control the order and flow of the data in iMacros using JavaScript, just basics will do. The few commands you need to know are,
iimDisplay:- Displays a short message in the iMacros browser.
This display the message like shown in the image within the imacro sidebar of firefox.
Syntax:
iimDisplay("Hello");
iimSet():- Defines variables for use inside the macro and assigns values to them.
Syntax:
j=112332423;
iimSet("numeber",j); //it assigns the value of "j" to "number"
To use this variable in the macro enter it as {{number}} like,
TAG POS=1 TYPE=INPUT:TEXT FORM=ID:register_form ATTR=ID:cust_number CONTENT={{number}}
iimPlay:- Plays a macro.
Syntax:
iimPlay("Demo-fill-form.iim");
iimDisplay:- Displays a short message in the iMacros browser.
This display the message like shown in the image within the imacro sidebar of firefox.
Syntax:
iimDisplay("Hello");
iimSet():- Defines variables for use inside the macro and assigns values to them.
Syntax:
j=112332423;
iimSet("numeber",j); //it assigns the value of "j" to "number"
To use this variable in the macro enter it as {{number}} like,
TAG POS=1 TYPE=INPUT:TEXT FORM=ID:register_form ATTR=ID:cust_number CONTENT={{number}}
iimPlay:- Plays a macro.
Syntax:
iimPlay("Demo-fill-form.iim");
iMacros - Why it is easy
iMacros is a browser automation tool, which comes for free in both Chrome and Firefox. This comes with record and replay functionality and this is considered as one of the best form filling automation extension. And if you know JavaScript you can do many more functionality combining iMacros with java script.
This is a very easy to use addon for browser. You just record whatever you want to do and replay it again, if you want you can even loop through the macro..
Pros:
Cons:
How it is done...
Record:
Play and Loop:
For more info http://wiki.imacros.net/
Tutorials click here
This is a very easy to use addon for browser. You just record whatever you want to do and replay it again, if you want you can even loop through the macro..
Pros:
- User-friendly, does the work in few clicks.
- Does not require any coding knowledge.
- Few tasks can be accomplished just by using few added lines which you always get from the wiki.
- It supports almost all scripting languages.
Cons:
- Cannot do complex testing using this addon.
- Coding knowledge is required to accomplish bigger tasks to have more easy control
How it is done...
Record:
- Click Record button and start doing the events.
- After recording all the events click stop, it will be saved in the name "#Current.iim" (.iim is the imacro file extension)
Play and Loop:
- Play the macro by clicking on the Play button to replay the macro.
- For running as the loop, enter the max loop value and click Loop.
For more info http://wiki.imacros.net/
Tutorials click here
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 ;)
Installing latest Xampp in ubuntu[Easy way]
Xampp for ubuntu includes apache, mysql, php and phpMyadmin.
Download the installer run file for linux from http://www.apachefriends.org/en/xampp-linux.html . Download the 64-bit version if your ubuntu is 64-bit to check your OS type :
XAMPP is now installed below the /opt/lampp directory.
Download the installer run file for linux from http://www.apachefriends.org/en/xampp-linux.html . Download the 64-bit version if your ubuntu is 64-bit to check your OS type :
- Open the terminal Type
uname -a
Linux discworld 2.6.38-8-generic #42-Ubuntu SMP Mon Apr 11 03:31:50 UTC 2011 i686 i686 i386GNU/Linux
whereas the 64-bit Ubuntu will show:
After the file download is complete, goto terminal and follow the steps belowLinux discworld 2.6.38-8-generic #42-Ubuntu SMP Mon Apr 11 03:31:50 UTC 2011 x86_64 x86_64x86_64 GNU/Linux
- Change working user to root, type "sudo su"
- Change your directory to your Downloads folder "cd /home/
/Downloads/" - Change the permissions to the installer "chmod 755 xampp-linux-1.8.2-0-installer.run"
- Run the installer "./xampp-linux-1.8.2-0-installer.run"
Important:
Before starting the xampp server you should setup the password for it to keep it secure, to do this
/opt/lampp/lampp security
and follow the instructions, it will ask you to set user and passwords for xampp,mysql, PhpMyAdmin and also network access for mysql daemon.
To start xampp
/opt/lampp/lampp start
To start xampp
/opt/lampp/lampp start
To stop xampp
/opt/lampp/lampp stop
Where it all started - Javascript
It all started when I started researching on Greasemonkey plugin, which gives you the flexibility to run JavaScript on any web page. Started trying sample scripts and it was cool. I started online learning javascript in code academy. Code Academy is a free online compiler where the courses are framed in such a way you learn as you code. It has a very easy interface and they start from the scratch. Rather watching youtube tutorial videos this is far far better way to learn.
External Links:-
Codeacademy.com
http://jsfiddle.net
After few courses I was successfully able to modify a javascript snippet and make it work without any errors for my personal use. A simple HTML table filter. It will hide the row if it matches the value you enter. The code is as below
External Links:-
Codeacademy.com
http://jsfiddle.net
After few courses I was successfully able to modify a javascript snippet and make it work without any errors for my personal use. A simple HTML table filter. It will hide the row if it matches the value you enter. The code is as below
hideRowsWithLargeCellValue("/html/body/table/tbody/tr[", 80, "]/td[", "]");
function hideRowsWithLargeCellValue(xpathPre, maxRows, xpathPost, maxpi) {
for (var J = maxRows; J >= 1; --J)
for(var i=1;i<=7;i++){
var srchRez = document.evaluate(xpathPre + J + xpathPost + i + maxpi, document, null, XPathResult.FIRST_ORDERED_NODE_TYPE, null);
if (srchRez.singleNodeValue && srchRez.singleNodeValue.textContent == "1") {
var rowToHide = srchRez.singleNodeValue.parentNode;
rowToHide.style.display = 'none';
}
}
}
This was a snippet taken from google and is edited according to my requirement. The jsfiddle link will explain with html example. This script will filter out all the rows that has "1" in any of the cell. To check how it works change "textContent == "1"" to "textContent == "0"" you can observe the difference in the result window.Jsfiddle link : - http://jsfiddle.net/aravindshadow/YeBL4/7/
Basic Linux commands
Before going to the command you should know what is the working user and why it is in root in the above image. As a root user you can modify,create,delete any files in any location. To change to root user type the command, "sudo su" and enter your login password. Because for a normal user most of the files are in-accessible and it doesn't allow to modify, move or delete.
I just have few better place to know the basic commands...
http://www.thegeekstuff.com/2010/11/50-linux-commands/
http://www.debianhelp.co.uk/commands.htm
Using Ubuntu as a Virtual Machine on windows 7
There are many application that gives the possibility to using multiple OS's in a single PC. One such is Oracle's VM VirtualBox. It is one of the top visualization product that supports both 32-bit and 64-bit of any OS. This is also a open source so you need not pay anything :)
Download Links:-
Virtualbox
Ubuntu
Download Links:-
Virtualbox
Ubuntu
I think this video is clear enough for the installation procedure. If you have any more queries please comment...
Advantages of using a Linux OS for development
Why Linux?
One of the best kernel that can provide great development platform and above all it is free of cost. Don't get panicked just with the name Linux it is not going to be full of scripts and codes we have crossed all those decades before. It is similar to windows interface and it is user-friendly.
There are lot of OS that run in Linux one of my favorite is ubuntu
One of the best kernel that can provide great development platform and above all it is free of cost. Don't get panicked just with the name Linux it is not going to be full of scripts and codes we have crossed all those decades before. It is similar to windows interface and it is user-friendly.
There are lot of OS that run in Linux one of my favorite is ubuntu
Subscribe to:
Comments (Atom)








