98 |
- |
1 |
<?xml version="1.0" encoding="ISO-8859-1" standalone="no"?>
|
|
|
2 |
<!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>
|
|
|
3 |
The stacked area plot is similar in appearance to the area plot, and this
|
|
|
4 |
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
|
|
|
5 |
plot type and data values. In the stacked area plot, PHPlot accumulates the
|
|
|
6 |
Y values at each X position, similar to the stacked bar plot, and fills the
|
|
|
7 |
area between the resulting values. For example, in 1960, 30% of the candy
|
|
|
8 |
sales were cherry, 10% were lime, and 6% were lemon. In the stacked area
|
|
|
9 |
plot, this is represented simply as (30, 10, 6, ...), whereas in the area
|
|
|
10 |
plot example we had to sum the values to get (100, 70, 60, 54, ...).
|
|
|
11 |
</p><p>
|
|
|
12 |
Also in this example we changed the legend using
|
|
|
13 |
<a class="xref" href="SetLegendReverse.html" title="SetLegendReverse"><span class="refentrytitle">SetLegendReverse</span></a> so the lines of text and color boxes
|
|
|
14 |
are in the same order as the area segments, bottom-to-top.
|
|
|
15 |
</p><p>
|
|
|
16 |
Note this plot type was added in PHPlot-5.1.1.
|
|
|
17 |
</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
|
|
|
18 |
# PHPlot Example: Stacked Area chart
|
|
|
19 |
require_once 'phplot.php';
|
|
|
20 |
|
|
|
21 |
$data = array(
|
|
|
22 |
array('1960', 30, 10, 6, 38, 14, 2),
|
|
|
23 |
array('1970', 20, 17, 9, 32, 2, 20),
|
|
|
24 |
array('1980', 20, 14, 12, 27, 2, 25),
|
|
|
25 |
array('1990', 5, 26, 15, 26, 18, 10),
|
|
|
26 |
array('2000', 28, 0, 18, 16, 33, 5),
|
|
|
27 |
);
|
|
|
28 |
|
|
|
29 |
$plot = new PHPlot(800, 600);
|
|
|
30 |
$plot->SetImageBorderType('plain');
|
|
|
31 |
|
|
|
32 |
$plot->SetPlotType('stackedarea');
|
|
|
33 |
$plot->SetDataType('text-data');
|
|
|
34 |
$plot->SetDataValues($data);
|
|
|
35 |
|
|
|
36 |
# Main plot title:
|
|
|
37 |
$plot->SetTitle('Candy Sales by Flavor');
|
|
|
38 |
|
|
|
39 |
# Set Y data limits, tick increment, and titles:
|
|
|
40 |
$plot->SetPlotAreaWorld(NULL, 0, NULL, 100);
|
|
|
41 |
$plot->SetYTickIncrement(10);
|
|
|
42 |
$plot->SetYTitle('% of Total');
|
|
|
43 |
$plot->SetXTitle('Year');
|
|
|
44 |
|
|
|
45 |
# Colors are significant to this data:
|
|
|
46 |
$plot->SetDataColors(array('red', 'green', 'blue', 'yellow', 'cyan', 'magenta'));
|
|
|
47 |
$plot->SetLegend(array('Cherry', 'Lime', 'Lemon', 'Banana', 'Apple', 'Berry'));
|
|
|
48 |
# Make legend lines go bottom to top, like the area segments (PHPlot > 5.4.0)
|
|
|
49 |
$plot->SetLegendReverse(True);
|
|
|
50 |
|
|
|
51 |
# Turn off X tick labels and ticks because they don't apply here:
|
|
|
52 |
$plot->SetXTickLabelPos('none');
|
|
|
53 |
$plot->SetXTickPos('none');
|
|
|
54 |
|
|
|
55 |
$plot->DrawGraph();
|
|
|
56 |
</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>
|