2.5. Multiple Lines Per Graph

Let's say we want to plot not just one dataset, but several Y values for each X position. With PHPlot, it is easy to specify the multiple data lines by just passing in all the Y values for a given X value at once. So instead of array('label', y), we specify array('label', y1, y2, y3, ...). This is very convenient when working with rows of data from databases.

Now our data will have three Y values for each position on the X axis.

//Include the code
require_once 'phplot.php';

//Define the object
$plot = new PHPlot(800,600);

//Set titles
$plot->SetTitle("A 3-Line Plot\nMade with PHPlot");
$plot->SetXTitle('X Data');
$plot->SetYTitle('Y Data');

//Define some data
$example_data = array(
     array('b',5,'',1),  // here we have a missing data point, that's ok

//Turn off X axis ticks and labels because they get in the way:

//Draw it

Which gives us:

Multiple lines on a graph

Notice that each set of Y data gets a different color. Also the missing data point (label 'b' on the green line) is skipped. This behavior can be adjusted with SetDrawBrokenLines.

This gives you the basics of how to create a graph in PHPlot. A nice start, but now we'd like to add some customization, namely different fonts, margins and types of graphs.

SourceForge.net Logo

This version of the manual was produced for the PHPlot Sourceforge project web service site, which requires the logo on each page.

To download a logo-free copy of the manual, see the PHPlot project downloads area.