Swiff Chart Generator is implemented as COM object and offers a variety of methods for managing and creating charts in Flash. Since COM objects are natively supported in PHP, running Swiff Chart Generator in your PHP pages is very simple.


To insert Swiff Chart Generator in a PHP page you must include a specific PHP file named SwiffChart.php on top of your PHP file. This included file contains all the necessary functions to let you access the Swiff Chart Generator API (Read PHP Reference manual of Swiff Chart Generator documentation for complete description of the API).


How does Swiff Chart Generator work in PHP pages?


Swiff Chart Generator offers you multiple possibilities to dynamically generate a chart. It allows you to:


One of the most straight forward strategy for dynamically generating a chart with Swiff Chart Generator consists in using 2 pages:

        <OBJECT CLASSID="clsid:D27CDB6E-AE6D-11cf-96B8-444553540000"
                WIDTH="400" 
                HEIGHT="300">
           <PARAM NAME=movie VALUE="gen_chart.php">:
        </OBJECT>

A simple PHP Example


The following example illustrates how simple it is to dynamically generate charts in Flash in a PHP page. As mentioned in the previous paragraph, the example involves 2 files and an additional Swiff Chart style file (.scs):

To install and run the example, simply download and copy these 4 files on your
Web site in the same directory.


PHP page: gen_chart.php

    <?php
    //Required include for manipulating chart object with PHP 
    require("SwiffChart.php");
  
    //Create a Chart Object 
    $chart= new SwiffChart;

    //Set the heading for the graph
    $chart->SetTitle( "My Chart" );

    //Set chart categories
    $chart->SetCategoriesFromString( "Q1;Q2;Q3" );

    //Fill chart series
    $chart->AddSeries();
    $chart->SetSeriesCaption( 0, "First Series" );
    $chart->SetSeriesValuesFromString( 0, "1.2;3.5;11.3" );

    $chart->AddSeries();
    $chart->SetSeriesCaption( 1, "Second Series" );
    $chart->SetSeriesValuesFromString( 1, "2.3;4.5;9.3" );

    $chart->AddSeries();
    $chart->SetSeriesCaption( 2, "Third Series" );
    $chart->SetSeriesValuesFromString( 2, "3.2;5.5;14.3" );

    //Define path to style document
    $style= "chart_style.scs";
    $style= stripslashes( dirname($PATH_TRANSLATED) . "\\\\" . $style );
    $chart->LoadStyle( $style );

    //Set the dimensions of the movie
    $chart->SetWidth( 400 );
    $chart->SetHeight( 300 );
    
    //Generate the Flash movie
    $chart->ExportAsResponse();
    ?>

HTML file: chart.html

    <HTML>
    <HEAD>
    <TITLE>Swiff Chart Generator - PHP Sample</TITLE>
    </HEAD>

    <BODY BGCOLOR="#FFFFFF" TEXT="#000000">

    <OBJECT CLASSID="clsid:D27CDB6E-AE6D-11cf-96B8-444553540000" 
            CODEBASE="http://download.macromedia.com/pub/shockwave/\
                      cabs/flash/swflash.cab#version=6,0,29,0" 
            WIDTH="400" 
            HEIGHT="300">
      <PARAM NAME=movie VALUE="gen_chart.php">
      <PARAM NAME=quality VALUE=high>
      <EMBED SRC="gen_chart.php" 
             QUALITY=high 
             PLUGINSPAGE="http://www.macromedia.com/shockwave/\
                          download/index.cgi?P1_Prod_Version=ShockwaveFlash" 
             TYPE="application/x-shockwave-flash" 
             WIDTH="400" 
             HEIGHT="300">
      </EMBED> 
    </OBJECT>

    </BODY>
    </HTML>

What you will obtain