5.52. Example - Squared Area Plot

This is a squared area plot (plot type squaredarea). It is similar to the area) plot, but the data lines are stepped as in the squared) plot.

Compare this image to the next example, Section 5.53, “Example - Stacked Squared Area Plot”, which uses the same data but plots a stacked (or cumulative) plot. This unstacked plot shows the actual values for each country (which can be read on the Y axis scale) but only if they are visible. For instance, in 2007 the amount for Venezuela (dark blue) is a little more than the amount for Nigeria (red). But in 2002-2003, the amounts for Canada (light blue) are less than the next two countries, which results in the Canada values being covered by the others and not visible.

In the script below, a copy of the last data row is appended to the data array. This is usually necessary with the squaredarea plot if you want the last data set to be visible. For an explanation, see description of the squaredarea plot type.

Note: Squared Area plots were added in PHPlot-6.2.0.

Example 5.52. Squared Area Plot

Squared Area Plot
# PHPlot Example: Squared Area plot
require_once 'phplot.php';

$title = "US Oil Imports by Country, Top 5\n"
       . "Non-cumulative (unstacked) Data";

$countries = array(
                'Canada', 'Saudi Arabia', 'Mexico', 'Venezuela', 'Nigeria',
#               --------  --------------  --------  -----------  ---------
$data = array(
  array('2002',     1445,           1519,     1500,        1201,      589),
  array('2003',     1549,           1726,     1569,        1183,      832),
  array('2004',     1616,           1495,     1598,        1297,     1078),
  array('2005',     1633,           1445,     1556,        1241,     1077),
  array('2006',     1802,           1423,     1577,        1142,     1037),
  array('2007',     1888,           1447,     1409,        1148,     1084),
  array('2008',     1956,           1503,     1187,        1039,      922),

# Append a duplicate of the last row, without label, to make it visible.
$n_rows = count($data);
$data[$n_rows] = $data[$n_rows-1];
$data[$n_rows][0] = '';

$plot = new PHPlot(800, 600);
$plot->SetYTitle('1000\'s of barrels per day');
# Make room for the legend to the left of the plot:
# Move the legend to the left:
$plot->SetLegendPixels(10, 10);
# To improve presentation in the manual:

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.