Subversion Repositories cheapmusic

Rev

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.52. Example - 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-boxplot2.html" title="5.51. Example - Box Plot with Outliers and Styles" /><link rel="next" href="ex-stackedsquaredarea1.html" title="5.53. Example - Stacked Squared Area Plot" /></head><body><div class="navheader"><table width="100%" summary="Navigation header"><tr><th colspan="3" align="center">5.52. Example - Squared Area Plot</th></tr><tr><td width="20%" align="left"><a accesskey="p" href="ex-boxplot2.html">Prev</a> </td><th width="60%" align="center">Chapter 5. PHPlot Examples</th><td width="20%" align="right"> <a accesskey="n" href="ex-stackedsquaredarea1.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-squaredarea1"></a>5.52. Example - Squared Area Plot</h2></div></div></div><p>
This is a squared area plot (plot type
<a class="link" href="conc-plottypes.html#plottype-squaredarea" title="3.4.13. Plot Type: squaredarea (Squared Area Plot)">squaredarea</a>).
It is similar to the <a class="link" href="conc-plottypes.html#plottype-area" title="3.4.1. Plot Type: area (Area Plot)">area</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 next example,
<a class="xref" href="ex-stackedsquaredarea1.html" title="5.53. Example - Stacked Squared Area Plot">Section 5.53, &#8220;Example - Stacked Squared Area Plot&#8221;</a>,
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.
</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 squaredarea 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-squaredarea" title="3.4.13. Plot Type: squaredarea (Squared Area Plot)">squaredarea</a> plot type.
</p><p>
Note: Squared Area plots were added in PHPlot-6.2.0.
</p><div class="example"><a id="example-squaredarea1"></a><p class="title"><strong>Example 5.52. Squared Area Plot</strong></p><div class="example-contents"><div class="informalfigure"><div class="mediaobject"><img src="examples/squaredarea1.png" alt="Squared Area Plot" /></div></div><pre class="programlisting">&lt;?php
# 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-&gt;SetTitle($title);
$plot-&gt;SetYTitle('1000\'s of barrels per day');
$plot-&gt;SetDataType('text-data');
$plot-&gt;SetDataValues($data);
$plot-&gt;SetPlotType('squaredarea');
$plot-&gt;SetXTickPos('none');
$plot-&gt;SetLineStyles('solid');
$plot-&gt;SetYTickIncrement(250);
$plot-&gt;SetLegend($countries);
# Make room for the legend to the left of the plot:
$plot-&gt;SetMarginsPixels(200);
# Move the legend to the left:
$plot-&gt;SetLegendPixels(10, 10);
# To improve presentation in the manual:
$plot-&gt;SetImageBorderType('plain');
$plot-&gt;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-boxplot2.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="ex-stackedsquaredarea1.html">Next</a></td></tr><tr><td width="40%" align="left" valign="top">5.51. Example - Box Plot with Outliers and Styles </td><td width="20%" align="center"><a accesskey="h" href="index.html">Home</a></td><td width="40%" align="right" valign="top"> 5.53. Example - Stacked Squared Area Plot</td></tr></table></div></body></html>