Blame | Last modification | View Log | RSS feed
<?xml version="1.0" encoding="ISO-8859-1" standalone="no"?>
<!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 wid
th="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>
This is a pie chart with the data array type 'text-data-single'.
This data type is only used with pie charts. Each record in the data array
simply contains a label (which is not used by PHPlot) and a segment size.
In this example, we use the label to identify the data for our own
reference, and then build a legend from those data labels along with the
data values. This is useful because by default PHPlot labels the segments with
only the percentage values. (Starting with PHPlot-5.6.0, there are new
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>.)
</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
# PHPlot Example: Pie/text-data-single
require_once 'phplot.php';
# The data labels aren't used directly by PHPlot. They are here for our
# reference, and we copy them to the legend below.
$data = array(
array('Australia', 7849),
array('Dem Rep Congo', 299),
array('Canada', 5447),
array('Columbia', 944),
array('Ghana', 541),
array('China', 3215),
array('Philippines', 791),
array('South Africa', 19454),
array('Mexico', 311),
array('United States', 9458),
array('USSR', 9710),
);
$plot = new PHPlot(800,600);
$plot->SetImageBorderType('plain');
$plot->SetPlotType('pie');
$plot->SetDataType('text-data-single');
$plot->SetDataValues($data);
# Set enough different colors;
$plot->SetDataColors(array('red', 'green', 'blue', 'yellow', 'cyan',
'magenta', 'brown', 'lavender', 'pink',
'gray', 'orange'));
# Main plot title:
$plot->SetTitle("World Gold Production, 1990\n(1000s of Troy Ounces)");
# Build a legend from our data array.
# Each call to SetLegend makes one line as "label: value".
foreach ($data as $row)
$plot->SetLegend(implode(': ', $row));
# Place the legend in the upper left corner:
$plot->SetLegendPixels(5, 5);
$plot->DrawGraph();
</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>