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.8. Example - Pie Chart, text-data-single</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-linepoints1.html" title="5.7. Example - Line/Point Plot, Point Shapes" /><link rel="next" href="ex-pie2.html" title="5.9. Example - Pie Chart, text-data" /></head><body><div class="navheader"><table width="100%" summary="Navigation header"><tr><th colspan="3" align="center">5.8. Example - Pie Chart, text-data-single</th></tr><tr><td width="20%" align="left"><a accesskey="p" href="ex-linepoints1.html">Prev</a> </td><th width="60%" align="center">Chapter 5. PHPlot Examples</th><td width="20%" align="right"> <a accesskey="n" href="ex-pie2.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-pie1"></a>5.8. Example - Pie Chart, text-data-single</h2></div></div></div><p>
|
|
|
3 |
This is a pie chart with the data array type 'text-data-single'.
|
|
|
4 |
This data type is only used with pie charts. Each record in the data array
|
|
|
5 |
simply contains a label (which is not used by PHPlot) and a segment size.
|
|
|
6 |
In this example, we use the label to identify the data for our own
|
|
|
7 |
reference, and then build a legend from those data labels along with the
|
|
|
8 |
data values. This is useful because by default PHPlot labels the segments with
|
|
|
9 |
only the percentage values. (Starting with PHPlot-5.6.0, there are new
|
|
|
10 |
options for labels. See <a class="xref" href="ex-pielabeltype.html" title="5.41. Example - Pie Chart Label Types">Section 5.41, “Example - Pie Chart Label Types”</a>.)
|
|
|
11 |
</p><div class="example"><a id="example-pie1"></a><p class="title"><strong>Example 5.8. Pie Chart, text-data-single</strong></p><div class="example-contents"><div class="informalfigure"><div class="mediaobject"><img src="examples/pie1.png" alt="Pie Chart text-data-single Example" /></div></div><pre class="programlisting"><?php
|
|
|
12 |
# PHPlot Example: Pie/text-data-single
|
|
|
13 |
require_once 'phplot.php';
|
|
|
14 |
|
|
|
15 |
# The data labels aren't used directly by PHPlot. They are here for our
|
|
|
16 |
# reference, and we copy them to the legend below.
|
|
|
17 |
$data = array(
|
|
|
18 |
array('Australia', 7849),
|
|
|
19 |
array('Dem Rep Congo', 299),
|
|
|
20 |
array('Canada', 5447),
|
|
|
21 |
array('Columbia', 944),
|
|
|
22 |
array('Ghana', 541),
|
|
|
23 |
array('China', 3215),
|
|
|
24 |
array('Philippines', 791),
|
|
|
25 |
array('South Africa', 19454),
|
|
|
26 |
array('Mexico', 311),
|
|
|
27 |
array('United States', 9458),
|
|
|
28 |
array('USSR', 9710),
|
|
|
29 |
);
|
|
|
30 |
|
|
|
31 |
$plot = new PHPlot(800,600);
|
|
|
32 |
$plot->SetImageBorderType('plain');
|
|
|
33 |
|
|
|
34 |
$plot->SetPlotType('pie');
|
|
|
35 |
$plot->SetDataType('text-data-single');
|
|
|
36 |
$plot->SetDataValues($data);
|
|
|
37 |
|
|
|
38 |
# Set enough different colors;
|
|
|
39 |
$plot->SetDataColors(array('red', 'green', 'blue', 'yellow', 'cyan',
|
|
|
40 |
'magenta', 'brown', 'lavender', 'pink',
|
|
|
41 |
'gray', 'orange'));
|
|
|
42 |
|
|
|
43 |
# Main plot title:
|
|
|
44 |
$plot->SetTitle("World Gold Production, 1990\n(1000s of Troy Ounces)");
|
|
|
45 |
|
|
|
46 |
# Build a legend from our data array.
|
|
|
47 |
# Each call to SetLegend makes one line as "label: value".
|
|
|
48 |
foreach ($data as $row)
|
|
|
49 |
$plot->SetLegend(implode(': ', $row));
|
|
|
50 |
# Place the legend in the upper left corner:
|
|
|
51 |
$plot->SetLegendPixels(5, 5);
|
|
|
52 |
|
|
|
53 |
$plot->DrawGraph();
|
|
|
54 |
</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-linepoints1.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-pie2.html">Next</a></td></tr><tr><td width="40%" align="left" valign="top">5.7. Example - Line/Point Plot, Point Shapes </td><td width="20%" align="center"><a accesskey="h" href="index.html">Home</a></td><td width="40%" align="right" valign="top"> 5.9. Example - Pie Chart, text-data</td></tr></table></div></body></html>
|