Subversion Repositories cheapmusic

Rev

Details | Last modification | View Log | RSS feed

Rev Author Line No. Line
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.19. Example - Bar Chart with 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-twoplot1.html" title="5.18. Example - Two Plots on One Image" /><link rel="next" href="ex-stackedbars3.html" title="5.20. Example - Stacked Bars with Y Data Value Labels" /></head><body><div class="navheader"><table width="100%" summary="Navigation header"><tr><th colspan="3" align="center">5.19. Example - Bar Chart with Data Value Labels</th></tr><tr><td width="20%" align="left"><a accesskey="p" href="ex-twoplot1.html">Prev</a> </td><th width="60%" align="center">Chapter 5. PHPlot Examples</th><td width="20%" align="right"> <a accesskey="n" href="ex-stackedbars3.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-bars4"></a>5.19. Example - Bar Chart with Data Value Labels</h2></div></div></div><p>
3
This is a bar chart with data value labels. Data value labels can be used as an
4
alternative to (or along with) Y tick labels, but only with bar and stackedbar
5
charts.
6
(Bar chart data value labels were added to PHPlot-5.0rc3.)
7
</p><div class="example"><a id="example-bars4"></a><p class="title"><strong>Example 5.19. Bar Chart with Data Value Labels</strong></p><div class="example-contents"><div class="informalfigure"><div class="mediaobject"><img src="examples/bars4.png" alt="Bar Chart with Data Value Labels Example" /></div></div><pre class="programlisting">&lt;?php
8
# PHPlot Example: Bar chart, with data labels
9
require_once 'phplot.php';
10
 
11
$data = array(
12
  array('China', 1306.31),           array('India', 1080.26),
13
  array('United States',  295.73),   array('Indonesia', 241.97),
14
  array('Brazil', 186.11),           array('Pakistan', 162.42),
15
  array('Bangladesh', 144.32),       array('Russia', 143.42),
16
);
17
 
18
$plot = new PHPlot(800, 600);
19
$plot-&gt;SetImageBorderType('plain');
20
$plot-&gt;SetPlotType('bars');
21
$plot-&gt;SetDataType('text-data');
22
$plot-&gt;SetDataValues($data);
23
$plot-&gt;SetTitle("World's Most Populous Countries\n2005 Population in Millions");
24
 
25
# Turn off X tick labels and ticks because they don't apply here:
26
$plot-&gt;SetXTickLabelPos('none');
27
$plot-&gt;SetXTickPos('none');
28
 
29
# Make sure Y=0 is displayed:
30
$plot-&gt;SetPlotAreaWorld(NULL, 0);
31
# Y Tick marks are off, but Y Tick Increment also controls the Y grid lines:
32
$plot-&gt;SetYTickIncrement(100);
33
 
34
# Turn on Y data labels:
35
$plot-&gt;SetYDataLabelPos('plotin');
36
 
37
# With Y data labels, we don't need Y ticks or their labels, so turn them off.
38
$plot-&gt;SetYTickLabelPos('none');
39
$plot-&gt;SetYTickPos('none');
40
 
41
# Format the Y Data Labels as numbers with 1 decimal place.
42
# Note that this automatically calls SetYLabelType('data').
43
$plot-&gt;SetPrecisionY(1);
44
 
45
$plot-&gt;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-twoplot1.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-stackedbars3.html">Next</a></td></tr><tr><td width="40%" align="left" valign="top">5.18. Example - Two Plots on One Image </td><td width="20%" align="center"><a accesskey="h" href="index.html">Home</a></td><td width="40%" align="right" valign="top"> 5.20. Example - Stacked Bars with Y Data Value Labels</td></tr></table></div></body></html>