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

SAMPLE: Simple XY 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 XY line chart in PHP.

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

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

  // Fill the first series named "Sales 2001"
  $seriesx1= "0.5" . $sep . "2.3" . $sep . "8.9" . $sep . "15.4";
  $seriesy1= "8" . $sep . "15" . $sep . "2" . $sep . "19";
  $chart->AddSeries();
  $chart->SetSeriesXValuesFromString(0, $seriesx1);
  $chart->SetSeriesYValuesFromString(0, $seriesy1);
  $chart->SetSeriesCaption(0, "Measure 1");

  // Fill the second series named "Sales 2002"
  $seriesx2= "0" . $sep . "3" . $sep . "5.2" . $sep . "10.8";
  $seriesy2= "23" . $sep . "8" . $sep .  "12" . $sep . "14";
  $chart->AddSeries();
  $chart->SetSeriesXValuesFromString(1, $seriesx2);
  $chart->SetSeriesYValuesFromString(1, $seriesy2);
  $chart->SetSeriesCaption(1, "Measure 2");

  // Set the chart title
  $chart->SetTitle("Experimental Results");

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

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

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

Keywords:PHP XY Line

Swiff Chart Generator