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.27. Example - Horizontal Bar Chart</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-colorcallbackbars.html" title="5.26. Example - Custom Bar Colors Using the Data Color Callback" /><link rel="next" href="ex-horizstackedbar.html" title="5.28. Example - Horizontal Stacked Bar Chart" /></head><body><div class="navheader"><table width="100%" summary="Navigation header"><tr><th colspan="3" align="center">5.27. Example - Horizontal Bar Chart</th></tr><tr><td width="20%" align="left"><a accesskey="p" href="ex-colorcallbackbars.html">Prev</a> </td><th width="60%" align="center">Chapter 5. PHPlot Examples</th><td width="20%" align="right"> <a accesskey="n" href="ex-horizstackedbar.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-horizbar"></a>5.27. Example - Horizontal Bar Chart</h2></div></div></div><p>
|
|
|
3 |
This example shows a horizontal bar chart.
|
|
|
4 |
As always, the X axis is horizontal, and the Y axis is vertical.
|
|
|
5 |
But the data array contains the X value for each implicit Y.
|
|
|
6 |
The data type 'text-data-yx' indicates this is a
|
|
|
7 |
horizontal plot.
|
|
|
8 |
</p><p>
|
|
|
9 |
This example also has a tiled background image under the plot area.
|
|
|
10 |
</p><div class="example"><a id="example-horizbar"></a><p class="title"><strong>Example 5.27. Horizontal Bar Chart</strong></p><div class="example-contents"><div class="informalfigure"><div class="mediaobject"><img src="examples/horizbar.png" alt="Horizontal Bar Chart Example" /></div></div><pre class="programlisting"><?php
|
|
|
11 |
# PHPlot Example - Horizontal Bars
|
|
|
12 |
require_once 'phplot.php';
|
|
|
13 |
|
|
|
14 |
$data = array(
|
|
|
15 |
array('San Francisco CA', 20.11),
|
|
|
16 |
array('Reno NV', 7.5),
|
|
|
17 |
array('Phoenix AZ', 8.3),
|
|
|
18 |
array('New York NY', 49.7),
|
|
|
19 |
array('New Orleans LA', 64.2),
|
|
|
20 |
array('Miami FL', 52.3),
|
|
|
21 |
array('Los Angeles CA', 13.2),
|
|
|
22 |
array('Honolulu HI', 18.3),
|
|
|
23 |
array('Helena MT', 11.3),
|
|
|
24 |
array('Duluth MN', 31.0),
|
|
|
25 |
array('Dodge City KS', 22.4),
|
|
|
26 |
array('Denver CO', 15.8),
|
|
|
27 |
array('Burlington VT', 36.1),
|
|
|
28 |
array('Boston MA', 42.5),
|
|
|
29 |
array('Barrow AL', 4.2),
|
|
|
30 |
);
|
|
|
31 |
|
|
|
32 |
$plot = new PHPlot(800, 800);
|
|
|
33 |
$plot->SetImageBorderType('plain'); // Improves presentation in the manual
|
|
|
34 |
$plot->SetTitle("Average Annual Precipitation (inches)\n"
|
|
|
35 |
. "Selected U.S. Cities");
|
|
|
36 |
$plot->SetBackgroundColor('gray');
|
|
|
37 |
# Set a tiled background image:
|
|
|
38 |
$plot->SetPlotAreaBgImage('images/drop.png', 'centeredtile');
|
|
|
39 |
# Force the X axis range to start at 0:
|
|
|
40 |
$plot->SetPlotAreaWorld(0);
|
|
|
41 |
# No ticks along Y axis, just bar labels:
|
|
|
42 |
$plot->SetYTickPos('none');
|
|
|
43 |
# No ticks along X axis:
|
|
|
44 |
$plot->SetXTickPos('none');
|
|
|
45 |
# No X axis labels. The data values labels are sufficient.
|
|
|
46 |
$plot->SetXTickLabelPos('none');
|
|
|
47 |
# Turn on the data value labels:
|
|
|
48 |
$plot->SetXDataLabelPos('plotin');
|
|
|
49 |
# No grid lines are needed:
|
|
|
50 |
$plot->SetDrawXGrid(FALSE);
|
|
|
51 |
# Set the bar fill color:
|
|
|
52 |
$plot->SetDataColors('salmon');
|
|
|
53 |
# Use less 3D shading on the bars:
|
|
|
54 |
$plot->SetShading(2);
|
|
|
55 |
$plot->SetDataValues($data);
|
|
|
56 |
$plot->SetDataType('text-data-yx');
|
|
|
57 |
$plot->SetPlotType('bars');
|
|
|
58 |
$plot->DrawGraph();
|
|
|
59 |
</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-colorcallbackbars.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-horizstackedbar.html">Next</a></td></tr><tr><td width="40%" align="left" valign="top">5.26. Example - Custom Bar Colors Using the Data Color Callback </td><td width="20%" align="center"><a accesskey="h" href="index.html">Home</a></td><td width="40%" align="right" valign="top"> 5.28. Example - Horizontal Stacked Bar Chart</td></tr></table></div></body></html>
|