In this post i would like to explain about how to implementing graphs using fusion charts. And implemented using PHP. In my previous post explained about How to calculate statistics in daily, weekly , monthly and yearly using php. Get the information using that post and implement the graph using this code. Create a xml file with specific feilds and download the fusion charts from the site. By following example i will explain. We can get the values from database and create xml file as mentioned.

This picture denotes : A graph for number of registrations over the year ( by monthly ) divided men and women.

how to implement graphs using fusion charts and php | Anil Labs

how to implement graphs using fusion charts and php | Anil Labs

1) Create a xml file :

 
In my previous post i have explained about how to calculate statistics in daily, weekly , monthly and yearly using php. By using this post we can get the categories.

1
 $dataFeildsArray={"Jan","Feb","Mar","Apr","May","Jun","Jul","Aug","Sep","Oct","Nov","Dec"};

Get the men registered numbers per month by using mysql quires.

1
2
3
4
5
6
for($d1=0;$d1<count($dataFeildsArray);$d1++){
  $get_users_query = "select *  from usertbl WHERE DATE_FORMAT( reg_date, '%Y.%M' ) =  '".'2011'.$months[$d1]."' AND gender='male'";
   $result = mysql_query($get_users_query);
   $dataArrayDay_men[] = mysql_num_rows($result);
  }
 // Same for women

 

Prepare XML file

 

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
<?php  
$strXMLYEAR = "<graph xaxisname='' yaxisname='No.Of Registrations' hovercapbg='F5589A' hovercapborder='F5589A' rotateNames='1' yAxisMaxValue='100' numdivlines='9' divLineColor='CCCCCC' divLineAlpha='80' decimalPrecision='0' showAlternateHGridColor='1' AlternateHGridAlpha='30' AlternateHGridColor='F5589A' caption='Registrations' subcaption='During a Year' >";
 
$strXMLYEAR .= "<categories font='Arial' fontSize='11' fontColor='000000'>";
 
for($i=(count($disp_months)-1);$i>=0;$i=$i-1){
    $strXMLYEAR .= "<category name='".$disp_months[$i]."' hoverText='".$disp_months[$i]."'/>";
    }
$strXMLYEAR .= "</categories><dataset seriesname='Men' color='FDC12E'>";
 
for($m1=(count($dataArrayDay_men)-1);$m1>=0;$m1=$m1-1){
    $strXMLYEAR .= "<set value='".$dataArrayDay_men[$m1]."' />";
    }
$strXMLYEAR .= "</dataset><dataset seriesname='Women' color='F5589A'>";
 
for($m1=(count($dataArrayDay_women)-1);$m1>=0;$m1=$m1-1){
    $strXMLYEAR .= "<set value='".$dataArrayDay_women[$m1]."' />";
    }
$strXMLYEAR .= "</dataset></graph>";
 
echo renderChart("Charts/FCF_MSColumn3D.swf", "", $strXMLYEAR, "productSales1235", 600, 300);
?>

Download fusion charts from from http://www.fusioncharts.com/


3 Comments

Alka · December 23, 2011 at 12:15 pm

Hi,

Packt Publshing is looking for Technical Reviewers on “FusionCharts: Beginner’s Guide” If interested in reviewing it, contact [email protected]

Mohit Gangrade · December 26, 2014 at 4:16 pm

That’s what i was looking for my admin panel. Thanks man you helped me complete my site 🙂

How to calculate statistics in daily, weekly , monthly and yearly using php - Anil Labs · September 30, 2013 at 12:45 pm

[…] We can write mysql quires using with these dates and get the details. and in the next post I will explain about how to implement graphs using fusion charts and php […]

Leave a Reply

Avatar placeholder

Your email address will not be published. Required fields are marked *