Blame | Last modification | View Log | RSS feed
<?xml version="1.0" encoding="ISO-8859-1" standalone="no"?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"><html xmlns="http://www.w3.org/1999/xhtml"><head><meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1" /><title>5.53. Example - Stacked Squared Area Plot</title><link rel="stylesheet" type="text/css" href="phplotdoc.css" /><meta name="generator" content="DocBook XSL Stylesheets V1.78.1" /><link rel="home" href="index.html" title="PHPlot Reference Manual" /><link rel="up" href="examples.html" title="Chapter 5. PHPlot Examples" /><link rel="prev" href="ex-squaredarea1.html" title="5.52. Example - Squared Area Plot" /><link rel="next" href="functions.html" title="Chapter 6. PHPlot Functions By Category" /></head><body><div class="navheader"><table width="100%" summary="Navigation header"><tr><th colspan="3" align="center">5.53. Example - Stacked Squared Area Plot</th></tr><tr><td width="20%" align="left"><a accesskey="p" href="ex-squaredarea1.html">Prev</a> </td><th width="6
0%" align="center">Chapter 5. PHPlot Examples</th><td width="20%" align="right"> <a accesskey="n" href="functions.html">Next</a></td></tr></table><hr /></div><div class="sect1"><div class="titlepage"><div><div><h2 class="title" style="clear: both"><a id="ex-stackedsquaredarea1"></a>5.53. Example - Stacked Squared Area Plot</h2></div></div></div><p>
This is a stacked squared area plot (plot type
<a class="link" href="conc-plottypes.html#plottype-stackedsquaredarea" title="3.4.16. Plot Type: stackedsquaredarea (Stacked Squared Area Plot)">stackedsquaredarea</a>).
It is similar to the <a class="link" href="conc-plottypes.html#plottype-stackedarea" title="3.4.14. Plot Type: stackedarea (Stacked Area Plot)">stackedarea</a>)
plot, but the data lines are stepped as in the
<a class="link" href="conc-plottypes.html#plottype-squared" title="3.4.12. Plot Type: squared (Squared Plot)">squared</a>) plot.
</p><p>
Compare this image to the previous example,
<a class="xref" href="ex-squaredarea1.html" title="5.52. Example - Squared Area Plot">Section 5.52, “Example - Squared Area Plot”</a>,
which uses the same data but plots an unstacked (or non-cumulative) plot.
In this stacked plot, all the data sets are visible because they are
accumulated from first (Canada, light blue) to last (Nigeria, red).
Unlike in the unstacked plot, you cannot read the per-country values from
the Y axis scale. But also unlike the unstacked plot, you can visually
compare the relative amounts from each country, and also read the overall
total at the top of the plot.
</p><p>
In the script below, a copy of the last data row is appended to the data array.
This is usually necessary with the stackedsquaredarea plot if you want the
last data set to be visible. For an explanation, see description of the
<a class="link" href="conc-plottypes.html#plottype-stackedsquaredarea" title="3.4.16. Plot Type: stackedsquaredarea (Stacked Squared Area Plot)">stackedsquaredarea</a> plot type.
</p><p>
Note: Stacked Squared Area plots were added in PHPlot-6.2.0.
</p><div class="example"><a id="example-stackedsquaredarea1"></a><p class="title"><strong>Example 5.53. Stacked Squared Area Plot</strong></p><div class="example-contents"><div class="informalfigure"><div class="mediaobject"><img src="examples/stackedsquaredarea1.png" alt="Stacked Squared Area Plot" /></div></div><pre class="programlisting"><?php
# PHPlot Example: Stacked Squared Area plot
require_once 'phplot.php';
$title = "US Oil Imports by Country, Top 5\n"
. "Cumulative (stacked) 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->SetTitle($title);
$plot->SetYTitle('1000\'s of barrels per day');
$plot->SetDataType('text-data');
$plot->SetDataValues($data);
$plot->SetPlotType('stackedsquaredarea');
$plot->SetXTickPos('none');
$plot->SetLineStyles('solid');
$plot->SetYTickIncrement(250);
$plot->SetLegend($countries);
# Make room for the legend to the left of the plot:
$plot->SetMarginsPixels(200);
# Move the legend to the left:
$plot->SetLegendPixels(10, 10);
# Flip the legend order for stacked plots:
$plot->SetLegendReverse(True);
# To improve presentation in the manual:
$plot->SetImageBorderType('plain');
$plot->DrawGraph();
</pre></div></div><br class="example-break" /></div><div class="navfooter"><hr /><table width="100%" summary="Navigation footer"><tr><td width="40%" align="left"><a accesskey="p" href="ex-squaredarea1.html">Prev</a> </td><td width="20%" align="center"><a accesskey="u" href="examples.html">Up</a></td><td width="40%" align="right"> <a accesskey="n" href="functions.html">Next</a></td></tr><tr><td width="40%" align="left" valign="top">5.52. Example - Squared Area Plot </td><td width="20%" align="center"><a accesskey="h" href="index.html">Home</a></td><td width="40%" align="right" valign="top"> Chapter 6. PHPlot Functions By Category</td></tr></table></div></body></html>