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.20. Example - Stacked Bars with Y Data Value Labels</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-bars4.html" title="5.19. Example - Bar Chart with Data Value Labels" /><link rel="next" href="ex-stackedarea1.html" title="5.21. Example - Stacked Area Plot" /></head><body><div class="navheader"><table width="100%" summary="Navigation header"><tr><th colspan="3" align="center">5.20. Example - Stacked Bars with Y Data Value Labels</th></tr><tr><td width="20%" align="left"><a accesskey="p" href="ex-bars4.html">Prev</a> </td><th width="60%" align="center">Chapter 5. PHPlot Examples</th><td width="20%" align="right"> <a accesskey="n" href="ex-stackedarea1.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-stackedbars3"></a>5.20. Example - Stacked Bars with Y Data Value Labels</h2></div></div></div><p>
|
|
|
3 |
This is the same as <a class="xref" href="ex-stackedbars2.html#example-stackedbars2" title="Example 5.15. Stacked Bars, Unshaded">Example 5.15, “Stacked Bars, Unshaded”</a> except that
|
|
|
4 |
Y data value labels are turned on.
|
|
|
5 |
Note this feature was added in PHPlot-5.1.1.
|
|
|
6 |
</p><div class="example"><a id="example-stackedbars3"></a><p class="title"><strong>Example 5.20. Stacked Bars with Y Data Value Labels</strong></p><div class="example-contents"><div class="informalfigure"><div class="mediaobject"><img src="examples/stackedbars3.png" alt="Stacked Bars with Y Data Value Labels Example" /></div></div><pre class="programlisting"><?php
|
|
|
7 |
# PHPlot Example: Stacked Bars, unshaded, with Y data labels
|
|
|
8 |
require_once 'phplot.php';
|
|
|
9 |
|
|
|
10 |
$data = array(
|
|
|
11 |
array('Jan', 40, 5, 10, 3), array('Feb', 90, 8, 15, 4),
|
|
|
12 |
array('Mar', 50, 6, 10, 4), array('Apr', 40, 3, 20, 4),
|
|
|
13 |
array('May', 75, 2, 10, 5), array('Jun', 45, 6, 15, 5),
|
|
|
14 |
array('Jul', 40, 5, 20, 6), array('Aug', 35, 6, 12, 6),
|
|
|
15 |
array('Sep', 50, 5, 10, 7), array('Oct', 45, 6, 15, 8),
|
|
|
16 |
array('Nov', 35, 6, 20, 9), array('Dec', 40, 7, 12, 9),
|
|
|
17 |
);
|
|
|
18 |
|
|
|
19 |
$plot = new PHPlot(800, 600);
|
|
|
20 |
$plot->SetImageBorderType('plain');
|
|
|
21 |
|
|
|
22 |
$plot->SetPlotType('stackedbars');
|
|
|
23 |
$plot->SetDataType('text-data');
|
|
|
24 |
$plot->SetDataValues($data);
|
|
|
25 |
|
|
|
26 |
$plot->SetTitle('Candy Sales by Month and Product');
|
|
|
27 |
$plot->SetYTitle('Millions of Units');
|
|
|
28 |
|
|
|
29 |
# No shading:
|
|
|
30 |
$plot->SetShading(0);
|
|
|
31 |
|
|
|
32 |
$plot->SetLegend(array('Chocolates', 'Mints', 'Hard Candy', 'Sugar-Free'));
|
|
|
33 |
# Make legend lines go bottom to top, like the bar segments (PHPlot > 5.4.0)
|
|
|
34 |
$plot->SetLegendReverse(True);
|
|
|
35 |
|
|
|
36 |
$plot->SetXTickLabelPos('none');
|
|
|
37 |
$plot->SetXTickPos('none');
|
|
|
38 |
|
|
|
39 |
# Turn on Y Data Labels: Both total and segment labels:
|
|
|
40 |
$plot->SetYDataLabelPos('plotstack');
|
|
|
41 |
|
|
|
42 |
$plot->DrawGraph();
|
|
|
43 |
</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-bars4.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-stackedarea1.html">Next</a></td></tr><tr><td width="40%" align="left" valign="top">5.19. Example - Bar Chart with 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.21. Example - Stacked Area Plot</td></tr></table></div></body></html>
|