You are viewing documentation for an older version. For current documentation - click here.

To plot multiple datasets we use Multiseries charts. Consider the Weekly Sales chart for two consecutive months. Here, for each week, we have two sets of data coming from current month and previous month.

Let's examine the following data for a multi-series chart.

Week
Current Month
Previous Month
 
Sales
Sales
Week 1
$40800
$38300
Week 2
$31400
$28400
Week 3
$26700
$15700
Week 4
$54400
$48100
 

Before you go further with this page, we recommend you to please see the previous page Creating First Chart as we start off from concepts explained in that page.

Let's go through the code that builds this chart:
 
<?php
         # Include FusionCharts PHP Class
           include('../Class/FusionCharts_Gen.php');
         # Create Multiseries Column3D chart object using FusionCharts PHP Class 
           $FC = new FusionCharts("MSColumn3D","350","300"); 
         # Set the relative path of the SWF file
           $FC->setSWFPath("../FusionCharts/");
         #  Store chart attributes in a variable 
           $strParam="caption=Weekly Sales;subcaption=Comparison;xAxisName=Week;yAxisName=Revenue;numberPrefix=$;decimalPrecision=0";
         # Set chart attributes 
           $FC->setChartParams($strParam);
         # Add category names
           $FC->addCategory("Week 1");
           $FC->addCategory("Week 2");
           $FC->addCategory("Week 3");
           $FC->addCategory("Week 4");
         # Create a new dataset 
           $FC->addDataset("This Month"); 
         # Add chart values for the above dataset
           $FC->addChartData("40800");
           $FC->addChartData("31400");
           $FC->addChartData("26700");
           $FC->addChartData("54400");
         # Create second dataset 
           $FC->addDataset("Previous Month"); 
         # Add chart values for the second dataset
           $FC->addChartData("38300");
           $FC->addChartData("28400");
           $FC->addChartData("15700");
           $FC->addChartData("48100");
      ?>
       <html>
           <head>
             <title>First Chart Using FusionCharts PHP Class</title>
             <script language='javascript' src='../FusionCharts/FusionCharts.js'></script>
           </head>
           <body>
          <?php
              # Render Chart 
              $FC->renderChart();
            ?>
          </body>
      </html>

As you can see in the above code, we're doing the following:

  • We include FusionCharts_Gen.php.

  • We create an object for Multi-series Column3D chart and set relative file path to the SWF file.

    $FC = new FusionCharts("MSColumn3D","350","300");
    $FC->setSWFPath("../FusionCharts/");

  • We store chart attributes in $strParam variable and pass it to setChartParams() function. It sets chart attributes.

  • For multi-series charts, we need to add the category names separately using addCategory() function.

    $FC->addCategory("Week 1");
    $FC->addCategory("Week 2");
    $FC->addCategory("Week 3");
    $FC->addCategory("Week 4");

  • Now, we need to define a dataset first. Hence we call addDataset() function. We set the dataset's name as 'This Month'.

    $FC->addDataset("This Month"); 
    

  • We provide chart data specific to the above dataset. Remember to provide chart data just after the dataset is defined. Unlike single series charts (as we saw in the First Chart example), we need not specify other chart parameters here.

    $FC->addChartData("40800");
    $FC->addChartData("31400");
    $FC->addChartData("26700");
    $FC->addChartData("54400");

    Please note that as we have 4 categories, we have entered 4 values for the dataset 'This Month'.

  • Next, we create the second dataset for 'Previous Month' and provide its data values.

    $FC->addDataset("Previous Month"); 
    $FC->addChartData("38300");
    $FC->addChartData("28400");
    $FC->addChartData("15700");
    $FC->addChartData("48100");

  • We add FusionCharts.js.

  • Finally, we render the chart.

    $FC->renderChart();
 
Please go through FusionCharts PHP Class API Reference section to know more about the functions used in the above code.

And the Multi-series chart is ready!