/ Home | Support | Swiff Chart Generator | Simple Line Chart - PHP
Knowledge Base

SAMPLE: Simple Line Chart - PHP

The information in this article applies to:

  • Swiff Chart Generator 2
  • Swiff Chart Generator 3

This example illustrates how to generate a simple line chart in PHP.

<?php 
  require( "SwiffChart.php" );
  
  $chart= new SwiffChart;

  $sep= ';';
  $ignoremultseparators= true;
  $chart->SetSeparators($sep, $ignoremultseparators);

  // Fill the categories
  $categories= "Q1" . $sep . "Q2" . $sep . "Q3" . $sep . "Q4";
  $chart->SetCategoriesFromString($categories);

  // Fill the first series named "Sales 2001"
  $series1= "8" . $sep . "15" . $sep . "6" . $sep . "19";
  $chart->AddSeries();
  $chart->SetSeriesValuesFromString(0, $series1);
  $chart->SetSeriesCaption(0, "Sales 2001");

  // Fill the second series named "Sales 2002"
  $series2= "23" . $sep . "8" . $sep . "12" . $sep . "14";
  $chart->AddSeries();
  $chart->SetSeriesValuesFromString(1, $series2);
  $chart->SetSeriesCaption(1, "Sales 2002");

  // Set the chart title
  $chart->SetTitle("Financial Results");
  $chart->SetSubtitle("(Values in M$ - Year to year results)");

  // Apply a Line style
  // The chart type is stored in the style file (*.scs)
  // Here the selected style is the predefined line style "Honolulu"
  $style = "line/Honolulu";
  $chart->LoadStyle( $style );
      
  $chart->SetWidth( 400 );
  $chart->SetHeight( 200 );
  $chart->SetLooping( false );

  $chart_res= $chart->GetHTMLTag();
?>

<H1>The Line Chart</H1>
<br><?=$chart_res?>

Keywords:PHP Line Chart

Swiff Chart Generator