How to implement graphs using fusion charts and php

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.

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

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

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

 

<?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/

Anil Kumar Panigrahi

With more than 10 years experience in PHP and Founder of Anil Labs, a blog for PHP and related posts. contributed posts regarding CodeIgniter, CakePHP and Learn PHP online ... Contact : [email protected]

You may also like...

3 Responses

  1. Alka says:

    Hi,

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

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

  1. September 30, 2013

    […] 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

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