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.4. Example - 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-area1.html" title="5.3. Example - Area Plot" /><link rel="next" href="ex-bars2.html" title="5.5. Example - Unshaded Bar Chart" /></head><body><div class="navheader"><table width="100%" summary="Navigation header"><tr><th colspan="3" align="center">5.4. Example - Bar Chart</th></tr><tr><td width="20%" align="left"><a accesskey="p" href="ex-area1.html">Prev</a> </td><th width="60%" align="center">Chapter 5. PHPlot Examples</th><td width="20%" align="right"> <a accesskey="n" href="ex-bars2.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-bars1"></a>5.4. Example - Bar Chart</h2></div></div></div><p>
|
|
|
3 |
This is a bar chart with three data sets plotted. The data type is
|
|
|
4 |
'text-data', so the X values are implicit. But the X values are
|
|
|
5 |
not relevant because the data labels (month names) are used instead,
|
|
|
6 |
and the X tick marks and labels are turned off. This plot uses the default
|
|
|
7 |
shading of bars.
|
|
|
8 |
</p><div class="example"><a id="example-bars1"></a><p class="title"><strong>Example 5.4. Bar Chart</strong></p><div class="example-contents"><div class="informalfigure"><div class="mediaobject"><img src="examples/bars1.png" alt="Bar Chart Example" /></div></div><pre class="programlisting"><?php
|
|
|
9 |
# PHPlot Example: Bar chart, 3 data sets, shaded
|
|
|
10 |
require_once 'phplot.php';
|
|
|
11 |
|
|
|
12 |
$data = array(
|
|
|
13 |
array('Jan', 40, 2, 4), array('Feb', 30, 3, 4), array('Mar', 20, 4, 4),
|
|
|
14 |
array('Apr', 10, 5, 4), array('May', 3, 6, 4), array('Jun', 7, 7, 4),
|
|
|
15 |
array('Jul', 10, 8, 4), array('Aug', 15, 9, 4), array('Sep', 20, 5, 4),
|
|
|
16 |
array('Oct', 18, 4, 4), array('Nov', 16, 7, 4), array('Dec', 14, 3, 4),
|
|
|
17 |
);
|
|
|
18 |
|
|
|
19 |
$plot = new PHPlot(800, 600);
|
|
|
20 |
$plot->SetImageBorderType('plain');
|
|
|
21 |
|
|
|
22 |
$plot->SetPlotType('bars');
|
|
|
23 |
$plot->SetDataType('text-data');
|
|
|
24 |
$plot->SetDataValues($data);
|
|
|
25 |
|
|
|
26 |
# Main plot title:
|
|
|
27 |
$plot->SetTitle('Shaded Bar Chart with 3 Data Sets');
|
|
|
28 |
|
|
|
29 |
# Make a legend for the 3 data sets plotted:
|
|
|
30 |
$plot->SetLegend(array('Engineering', 'Manufacturing', 'Administration'));
|
|
|
31 |
|
|
|
32 |
# Turn off X tick labels and ticks because they don't apply here:
|
|
|
33 |
$plot->SetXTickLabelPos('none');
|
|
|
34 |
$plot->SetXTickPos('none');
|
|
|
35 |
|
|
|
36 |
$plot->DrawGraph();
|
|
|
37 |
</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-area1.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-bars2.html">Next</a></td></tr><tr><td width="40%" align="left" valign="top">5.3. Example - Area Plot </td><td width="20%" align="center"><a accesskey="h" href="index.html">Home</a></td><td width="40%" align="right" valign="top"> 5.5. Example - Unshaded Bar Chart</td></tr></table></div></body></html>
|