Implementation Methods > PHP/CF/CGI/Perl Implementation
 
Analogically, using FusionCharts with PHP/CF/CGI/Perl is very similar to using it with ASP/ASP.NET, but for the changes in data connection and retrieval modules.

In this part, we will discuss the modal integration of FusionCharts with PHP/CF/CGI/Perl. We wouldn’t go much into the code level of these scripting languages.

You can use either of the two methods mentioned below to provide data to FusionCharts:

  1. dataURL way – using this way you provide the URL of XML Document (or XML relaying Doc) to FusionCharts and FusionCharts retrieves the data from that specified location.
  2. dataXML way – using this way you provide the complete chunk of XML data to FusionCharts and FusionCharts uses this chunk to render the graph.

So, let’s first see the dataURL way with PHP/CF/CGI/Perl. With either of the aforementioned languages, you need to have two pages:

  1. The Graph Container Page – i.e., the Page which embeds the graph using the OBJECT/EMBED tags. This page could be a simple HTML page also.
  2. The data provider Page – This is the actual PHP/CF/CGI/Perl script page that would provide the data to FusionCharts upon retrieving any parameters sent to it.

Let’s now study an analogical model for this mode. We consider Graph.html to be the page which contains the graph object. It contains the normal HTML code as usual:

<HTML>
<HEAD>
<TITLE>FusionCharts ASP Chart</TITLE>
</HEAD>
<BODY bgcolor="#FFFFFF">
<CENTER>
<OBJECT classid="clsid:D27CDB6E-AE6D-11cf-96B8-444553540000"
codebase="http://download.macromedia.com/pub/shockwave/
cabs/flash/swflash.cab#version=5,0,0,0"
WIDTH="565" HEIGHT="420" id="FCColumn" ALIGN="">
<PARAM NAME=movie VALUE="FC2Column.swf?dataUrl=ProvideData.php*Param1=Value1*Param2=Value2">
<PARAM NAME=quality VALUE=high>
<PARAM NAME=bgcolor VALUE=#FFFFFF>
<EMBED src="FC2Column.swf?dataUrl= ProvideData.php*Param1=Value1*Param2=Value2" quality=high
bgcolor=#FFFFFF WIDTH="565" HEIGHT="420" NAME="FCColumn"
ALIGN="" TYPE="application/x-shockwave-flash"
PLUGINSPAGE="http://www.macromedia.com/go/getflashplayer"></EMBED>
</OBJECT>
</CENTER>
</BODY>
</HTML>
As you can see above, we have mentioned ProvideData.php as the data provider page and to this page we have passed two parameters (as QueryString) namely Param1 (with value as Value1) and Param2 (with value as Value2).

Now, getting to ProvideData.php – this page’s main function is to request the data sent to it as QueryString, interact with the database (if required) and then format and output the XML string required by FusionCharts. The task can be broken down into the following steps:
  1. Initialize the page (depending on the script you are using).
  2. Request the form data sent to it as query string
  3. Interact with the database (or other forms of storage systems) based on the parameters retrieved.
  4. Loop through the output of the database (/other systems) to form an XML document (in the format required by FusionCharts). You could either use string concatenation methods to form an XML document or DOM/Object methods (if provided by your script) to form it.
  5. Write that XML document to the output stream

 

That’s all you need to do to have FusionCharts work with your PHP/CF/CGI/Perl script in the dataUrl way.
 
The dataXML way
Now, if you want to use dataXML way to provide data to FusionCharts, your page structure would look something as under:
  1. (Initialize Page)
  2. (Interact with database/other forms of storage and get the output)
  3. (Use the database output to form an XML document – again using string concatenation methods or DOM/Object methods – let’s say stored in a variable strXML)
  4. (Write other HTML code off – template etc.)
  5. (Now, the code for graph)
    <OBJECT classid="clsid:D27CDB6E-AE6D-11cf-96B8-444553540000"
    codebase="http://download.macromedia.com/pub/shockwave/
    cabs/flash/swflash.cab#version=5,0,0,0"
    WIDTH="565" HEIGHT="420" id="FCColumn" ALIGN="">
    <PARAM NAME=movie VALUE="FC2Column.swf">
    <PARAM NAME=FlashVars value="&dataXML=(* strXML*)">
    <PARAM NAME=quality VALUE=high>
    <PARAM NAME=bgcolor VALUE=#FFFFFF>
    <EMBED src="FC2Column.swf" FlashVars="&dataXML=(* strXML*)" quality=high
    bgcolor=#FFFFFF WIDTH="565" HEIGHT="420" NAME="FCColumn"
    ALIGN="" TYPE="application/x-shockwave-flash"
    PLUGINSPAGE="http://www.macromedia.com/go/getflashplayer"></EMBED>
    </OBJECT>
  6. (Write off the closing HTML Tags)
  7. (End the page).