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.3. Example - 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-lines2.html" title="5.2. Example - Line Plot: Functions" /><link rel="next" href="ex-bars1.html" title="5.4. Example - Bar Chart" /></head><body><div class="navheader"><table width="100%" summary="Navigation header"><tr><th colspan="3" align="center">5.3. Example - Area Plot</th></tr><tr><td width="20%" align="left"><a accesskey="p" href="ex-lines2.html">Prev</a> </td><th width="60%" align="center">Chapter 5. PHPlot Examples</th><td width="20%" align="right"> <a accesskey="n" href="ex-bars1.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-area1"></a>5.3. Example - Area Plot</h2></div></div></div><p>
|
|
|
3 |
In the area plot, PHPlot fills the area from each data set down to the
|
|
|
4 |
next data set, or to the X axis for the last data set.
|
|
|
5 |
For this example, the data was prepared such that the data sets are
|
|
|
6 |
cumulative percentages.
|
|
|
7 |
(See also <a class="xref" href="ex-stackedarea1.html#example-stackedarea1" title="Example 5.21. Stacked Area Plot">Example 5.21, “Stacked Area Plot”</a> which produces a similar
|
|
|
8 |
plot using a different data representation.)
|
|
|
9 |
</p><div class="example"><a id="example-area1"></a><p class="title"><strong>Example 5.3. Area Plot</strong></p><div class="example-contents"><div class="informalfigure"><div class="mediaobject"><img src="examples/area1.png" alt="Area Plot Example" /></div></div><pre class="programlisting"><?php
|
|
|
10 |
# PHPlot Example: Area chart, 6 areas.
|
|
|
11 |
require_once 'phplot.php';
|
|
|
12 |
|
|
|
13 |
$data = array(
|
|
|
14 |
array('1960', 100, 70, 60, 54, 16, 2),
|
|
|
15 |
array('1970', 100, 80, 63, 54, 22, 20),
|
|
|
16 |
array('1980', 100, 80, 66, 54, 27, 25),
|
|
|
17 |
array('1990', 100, 95, 69, 54, 28, 10),
|
|
|
18 |
array('2000', 100, 72, 72, 54, 38, 5),
|
|
|
19 |
);
|
|
|
20 |
|
|
|
21 |
$plot = new PHPlot(800, 600);
|
|
|
22 |
$plot->SetImageBorderType('plain');
|
|
|
23 |
|
|
|
24 |
$plot->SetPlotType('area');
|
|
|
25 |
$plot->SetDataType('text-data');
|
|
|
26 |
$plot->SetDataValues($data);
|
|
|
27 |
|
|
|
28 |
# Main plot title:
|
|
|
29 |
$plot->SetTitle('Candy Sales by Flavor');
|
|
|
30 |
|
|
|
31 |
# Set Y data limits, tick increment, and titles:
|
|
|
32 |
$plot->SetPlotAreaWorld(NULL, 0, NULL, 100);
|
|
|
33 |
$plot->SetYTickIncrement(10);
|
|
|
34 |
$plot->SetYTitle('% of Total');
|
|
|
35 |
$plot->SetXTitle('Year');
|
|
|
36 |
|
|
|
37 |
# Colors are significant to this data:
|
|
|
38 |
$plot->SetDataColors(array('red', 'green', 'blue', 'yellow', 'cyan', 'magenta'));
|
|
|
39 |
$plot->SetLegend(array('Cherry', 'Lime', 'Lemon', 'Banana', 'Apple', 'Berry'));
|
|
|
40 |
|
|
|
41 |
# Turn off X tick labels and ticks because they don't apply here:
|
|
|
42 |
$plot->SetXTickLabelPos('none');
|
|
|
43 |
$plot->SetXTickPos('none');
|
|
|
44 |
|
|
|
45 |
$plot->DrawGraph();
|
|
|
46 |
</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-lines2.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-bars1.html">Next</a></td></tr><tr><td width="40%" align="left" valign="top">5.2. Example - Line Plot: Functions </td><td width="20%" align="center"><a accesskey="h" href="index.html">Home</a></td><td width="40%" align="right" valign="top"> 5.4. Example - Bar Chart</td></tr></table></div></body></html>
|