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.21. Example - Stacked 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-stackedbars3.html" title="5.20. Example - Stacked Bars with Y Data Value Labels" /><link rel="next" href="ex-annotate.html" title="5.22. Example - Annotating a Plot Using a Callback" /></head><body><div class="navheader"><table width="100%" summary="Navigation header"><tr><th colspan="3" align="center">5.21. Example - Stacked Area Plot</th></tr><tr><td width="20%" align="left"><a accesskey="p" href="ex-stackedbars3.html">Prev</a>
</td><th width="60%" align="center">Chapter 5. PHPlot Examples</th><td width="20%" align="right"> <a accesskey="n" href="ex-annotate.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-stackedarea1"></a>5.21. Example - Stacked Area Plot</h2></div></div></div><p>
The stacked area plot is similar in appearance to the area plot, and this
example is the same as in <a class="xref" href="ex-area1.html" title="5.3. Example - Area Plot">Section 5.3, “Example - Area Plot”</a> except for the
plot type and data values. In the stacked area plot, PHPlot accumulates the
Y values at each X position, similar to the stacked bar plot, and fills the
area between the resulting values. For example, in 1960, 30% of the candy
sales were cherry, 10% were lime, and 6% were lemon. In the stacked area
plot, this is represented simply as (30, 10, 6, ...), whereas in the area
plot example we had to sum the values to get (100, 70, 60, 54, ...).
</p><p>
Also in this example we changed the legend using
<a class="xref" href="SetLegendReverse.html" title="SetLegendReverse"><span class="refentrytitle">SetLegendReverse</span></a> so the lines of text and color boxes
are in the same order as the area segments, bottom-to-top.
</p><p>
Note this plot type was added in PHPlot-5.1.1.
</p><div class="example"><a id="example-stackedarea1"></a><p class="title"><strong>Example 5.21. Stacked Area Plot</strong></p><div class="example-contents"><div class="informalfigure"><div class="mediaobject"><img src="examples/stackedarea1.png" alt="Stacked Area Plot Example" /></div></div><pre class="programlisting"><?php
# PHPlot Example: Stacked Area chart
require_once 'phplot.php';
$data = array(
array('1960', 30, 10, 6, 38, 14, 2),
array('1970', 20, 17, 9, 32, 2, 20),
array('1980', 20, 14, 12, 27, 2, 25),
array('1990', 5, 26, 15, 26, 18, 10),
array('2000', 28, 0, 18, 16, 33, 5),
);
$plot = new PHPlot(800, 600);
$plot->SetImageBorderType('plain');
$plot->SetPlotType('stackedarea');
$plot->SetDataType('text-data');
$plot->SetDataValues($data);
# Main plot title:
$plot->SetTitle('Candy Sales by Flavor');
# Set Y data limits, tick increment, and titles:
$plot->SetPlotAreaWorld(NULL, 0, NULL, 100);
$plot->SetYTickIncrement(10);
$plot->SetYTitle('% of Total');
$plot->SetXTitle('Year');
# Colors are significant to this data:
$plot->SetDataColors(array('red', 'green', 'blue', 'yellow', 'cyan', 'magenta'));
$plot->SetLegend(array('Cherry', 'Lime', 'Lemon', 'Banana', 'Apple', 'Berry'));
# Make legend lines go bottom to top, like the area segments (PHPlot > 5.4.0)
$plot->SetLegendReverse(True);
# Turn off X tick labels and ticks because they don't apply here:
$plot->SetXTickLabelPos('none');
$plot->SetXTickPos('none');
$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-stackedbars3.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-annotate.html">Next</a></td></tr><tr><td width="40%" align="left" valign="top">5.20. Example - Stacked Bars with Y Data Value Labels </td><td width="20%" align="center"><a accesskey="h" href="index.html">Home</a></td><td width="40%" align="right" valign="top"> 5.22. Example - Annotating a Plot Using a Callback</td></tr></table></div></body></html>