This repository has been archived on 2024-04-08. You can view files and clone it, but cannot push or open issues or pull requests.
phptsmadmin/includes/jpgraph/docs/chunkhtml/ch16.html

891 lines
101 KiB
HTML
Raw Normal View History

2011-05-28 09:51:52 +00:00
<html><head><meta http-equiv="Content-Type" content="text/html; charset=UTF-8"><title>Chapter 16. Non-Linear graph types</title><link rel="stylesheet" type="text/css" href="manual.css"><meta name="generator" content="DocBook XSL Stylesheets V1.76.0"><link rel="home" href="index.html" title="JpGraph Manual"><link rel="up" href="pt04.html" title="Part IV. Creating linear and non-linear graphs"></head><body bgcolor="white" text="black" link="#0000FF" vlink="#840084" alink="#0000FF"><div class="navheader"><table width="100%" summary="Navigation header"><tr><th colspan="3" align="center">Chapter 16. Non-Linear graph types</th></tr><tr><td width="20%" align="left"> </td><th width="60%" align="center">Part IV. Creating linear and non-linear graphs</th><td width="20%" align="right"> </td></tr></table><hr></div><div class="chapter" title="Chapter 16. Non-Linear graph types"><div class="titlepage"><div><div><h2 class="title"><a name="id2554047"></a>Chapter 16. Non-Linear graph types</h2></div></div></div><div class="toc"><p><b>Table of Contents</b></p><dl><dt><span class="sect1"><a href="ch16.html#id2564821">16.1. Pie graphs</a></span></dt><dd><dl><dt><span class="sect2"><a href="ch16.html#id2564943">16.1.1. Hare/Niemeyer Integer compensation for Pie Plots</a></span></dt><dt><span class="sect2"><a href="ch16.html#sec.pie-plots2d">16.1.2. 2D-Pie plots</a></span></dt><dt><span class="sect2"><a href="ch16.html#sec.pie-plots3d">16.1.3. 3D-Pie plots</a></span></dt><dt><span class="sect2"><a href="ch16.html#sec.ring-plots">16.1.4. Ring plots</a></span></dt><dt><span class="sect2"><a href="ch16.html#id2566405">16.1.5. Exploding pie slices</a></span></dt><dt><span class="sect2"><a href="ch16.html#id2566418">16.1.6. Specifying and adjusting labels on pie plots</a></span></dt><dt><span class="sect2"><a href="ch16.html#id2566836">16.1.7. Adding drop shadows to the slices</a></span></dt><dt><span class="sect2"><a href="ch16.html#sec.pie-image-background">16.1.8. Adding background images to Pie graphs</a></span></dt><dt><span class="sect2"><a href="ch16.html#sec.pie-color-themes">16.1.9. Specifying slice colors and using themes</a></span></dt></dl></dd><dt><span class="sect1"><a href="ch16s02.html">16.2. Radar graphs</a></span></dt><dd><dl><dt><span class="sect2"><a href="ch16s02.html#id2567444">16.2.1. Adding radar plots to a radar graph</a></span></dt><dt><span class="sect2"><a href="ch16s02.html#id2567446">16.2.2. Adding plot-marks to radar plots</a></span></dt><dt><span class="sect2"><a href="ch16s02.html#id2567709">16.2.3. Client Side Image maps</a></span></dt><dt><span class="sect2"><a href="ch16s02.html#id2567731">16.2.4. Adjusting the overall properties of the radar graph</a></span></dt><dt><span class="sect2"><a href="ch16s02.html#id2567884">16.2.5. Adjusting the axis formatting</a></span></dt><dt><span class="sect2"><a href="ch16s02.html#id2568086">16.2.6. Adjusting grid lines for the radar graph</a></span></dt><dt><span class="sect2"><a href="ch16s02.html#id2568340">16.2.7. Using a logarithmic scale</a></span></dt><dt><span class="sect2"><a href="ch16s02.html#id2568414">16.2.8. Enabling anti-aliasing for radar graphs</a></span></dt><dt><span class="sect2"><a href="ch16s02.html#id2568558">16.2.9. A final example</a></span></dt></dl></dd><dt><span class="sect1"><a href="ch16s03.html">16.3. Polar graphs</a></span></dt><dd><dl><dt><span class="sect2"><a href="ch16s03.html#id2568891">16.3.1. Rotating the polar graph</a></span></dt><dt><span class="sect2"><a href="ch16s03.html#id2568920">16.3.2. Changing the angle direction</a></span></dt><dt><span class="sect2"><a href="ch16s03.html#id2569025">16.3.3. Adding polar plots to a polar graph</a></span></dt><dt><span class="sect2"><a href="ch16s03.html#id2569090">16.3.4. Adding plot-marks to polar plots</a></span></dt><dt><span class="sect2"><a href="ch16s03.html#id2569156">16.3.5. Client Side Image maps</a></span></dt><dt><span class="sect2"><a href="ch16s03.html#id2569166">16.3.6. Adjusting the radius scale</a></span></dt><dt><span class="sect2"><a href="ch16s03.html#id2569422
<p>All the plots we have discussed up to now have used some kind of x-y coordinate
system. The library supports a number of graph types that does not use rectangular axis
or scales. The supported graphs are shown below</p>
<p>
</p><div class="informaltable">
<table border="0"><colgroup><col class="c1"><col class="c2"><col class="c3"></colgroup><tbody><tr><td align="center">
<p>
</p><div class="figure"><a name="id2564680"></a><p class="title"><b>Figure 16.1. Pie graphs</b></p><div class="figure-contents">
<div class="mediaobject"><img src="images/ploticon_pie2d.png" alt="Pie graphs"></div>
</div></div><p><br class="figure-break">
</p>
<p>(See <a class="xref" href="ch16.html#sec.pie-plots2d" title="2D-Pie plots">2D-Pie plots</a>)</p>
</td><td align="center">
<p>
</p><div class="figure"><a name="id2564720"></a><p class="title"><b>Figure 16.2. Pie3D graphs</b></p><div class="figure-contents">
<div class="mediaobject"><img src="images/ploticon_pie3d.png" alt="Pie3D graphs"></div>
</div></div><p><br class="figure-break">
</p>
<p>(See <a class="xref" href="ch16.html#sec.pie-plots3d" title="3D-Pie plots">3D-Pie plots</a>)</p>
</td><td align="center">
<p>
</p><div class="figure"><a name="id2564763"></a><p class="title"><b>Figure 16.3. Ring graphs</b></p><div class="figure-contents">
<div class="mediaobject"><img src="images/ploticon_ring.png" alt="Ring graphs"></div>
</div></div><p><br class="figure-break">
</p>
<p>(See <a class="xref" href="ch16.html#sec.ring-plots" title="Ring plots">Ring plots</a>)</p>
</td></tr><tr><td align="center">
<p>
</p><div class="figure"><a name="id2564805"></a><p class="title"><b>Figure 16.4. Radar graphs</b></p><div class="figure-contents">
<div class="mediaobject"><img src="images/ploticon_radar.png" alt="Radar graphs"></div>
</div></div><p><br class="figure-break">
</p>
<p>(See <a class="xref" href="ch16s02.html" title="Radar graphs">Radar graphs</a>)</p>
</td><td align="center">
<p>
</p><div class="figure"><a name="id2564846"></a><p class="title"><b>Figure 16.5. Polar graphs</b></p><div class="figure-contents">
<div class="mediaobject"><img src="images/ploticon_polar.png" alt="Polar graphs"></div>
</div></div><p><br class="figure-break">
</p>
<p>(See <a class="xref" href="ch16s03.html" title="Polar graphs">Polar graphs</a>)</p>
</td><td align="center">
<p>
</p><div class="figure"><a name="id2564888"></a><p class="title"><b>Figure 16.6. Gantt charts</b></p><div class="figure-contents">
<div class="mediaobject"><img src="images/ploticon_gantt.png" alt="Gantt charts"></div>
</div></div><p><br class="figure-break">
</p>
<p>(See <a class="xref" href="ch16s04.html" title="Gantt charts">Gantt charts</a>)</p>
</td></tr></tbody></table>
</div><p>
</p>
<div class="sect1" title="Pie graphs"><div class="titlepage"><div><div><h2 class="title" style="clear: both"><a name="id2564821"></a>Pie graphs</h2></div></div></div>
<p>The main difference compared to the previous discussed x-y plots is that to all
pie plots are added based on the class <code class="code">PieGraph</code> instead of the
<code class="code">Graph</code> class used for all x-y graphs.</p>
<div class="sect2" title="Hare/Niemeyer Integer compensation for Pie Plots"><div class="titlepage"><div><div><h3 class="title"><a name="id2564943"></a>Hare/Niemeyer Integer compensation for Pie Plots</h3></div></div></div>
<p>A problem that sometimes occur with the use of integer values for Pie charts
is the problem with rounding error. Even with correct rounding of the individual
pie slices using only integers as display values have the problem that it
sometimes doesn't sum up to 100% as illustrated in <a class="xref" href="ch16.html#fig.hare-niemeyer" title="Figure 16.7. Hare/Niemeyer pie plot integer compensation">Figure 16.7. Hare/Niemeyer pie plot integer compensation</a></p>
<p>This is in many circumstances not acceptable. The library includes the
Hare/Niemeyer compensation that can be enabled. This will adjust the integer
values so that it always sum up to 100%. The result of the compensation can be
seen in <a class="xref" href="ch16.html#fig.hare-niemeyer" title="Figure 16.7. Hare/Niemeyer pie plot integer compensation">Figure 16.7. Hare/Niemeyer pie plot integer compensation</a></p>
<p>
</p><div class="figure"><a name="fig.hare-niemeyer"></a><p class="title"><b>Figure 16.7. Hare/Niemeyer pie plot integer compensation</b></p><div class="figure-contents">
<div class="informaltable">
<table border="0"><colgroup><col class="c1"><col class="c2"></colgroup><tbody><tr><td align="center">
<p><span class="inlinemediaobject"><img src="images/piepercent1.png" alt="Hare/Niemeyer pie plot integer compensation"></span></p>
<p>a) Problem with integer values </p>
</td><td align="center">
<p><span class="inlinemediaobject"><img src="images/piepercent2.png" alt="Hare/Niemeyer pie plot integer compensation"></span></p>
<p>b) Hare/Niemeyer compensation </p>
</td></tr></tbody></table>
</div>
</div></div><p><br class="figure-break">
</p>
<div class="note" title="Note" style="margin-left: 0.5in; margin-right: 0.5in;"><h3 class="title">Note</h3>
<p>To enable this compensation the label type should be specified as </p>
<p>
</p><div class="hl-main"><table class="hl-table" width="100%"><tr><td class="hl-gutter" align="right" valign="top"><pre>1
</pre></td><td class="hl-main" valign="top"><pre><span class="hl-code">$pieplot-&gt;SetLabelType(PIE_VALUE_ADJPERCENTAGE);</span></pre></td></tr></table></div><p>
</p>
</div>
</div>
<div class="sect2" title="2D-Pie plots"><div class="titlepage"><div><div><h3 class="title"><a name="sec.pie-plots2d"></a>2D-Pie plots</h3></div></div></div>
<p>In order to create Pie plots the module "<code class="filename">jpgraph_pie.php</code>"
must first be included. </p>
<p>The principle for creating Pie graphs follows the same structure as for line
graphs. First an instance of <code class="code">class PieGraph</code> is created and then one
or several instances of <code class="code">class PiePlot</code> is created and added to the
<code class="code">PieGraph</code> instance as the following basic example shows</p>
<p>
</p><div class="example"><a name="example.example26"></a><p class="title"><b>Example 16.1. A basic Pie graph (<code class="filename">example26.php</code>) </b></p><div class="example-contents"> <div class="hl-main"><table class="hl-table" width="100%"><tr><td class="hl-gutter" align="right" valign="top"><pre>1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
</pre></td><td class="hl-main" valign="top"><pre><span class="hl-inlinetags">&lt;?php</span><span class="hl-code"> </span><span class="hl-comment">//</span><span class="hl-comment"> content=&quot;text/plain; charset=utf-8&quot;</span><span class="hl-comment"></span><span class="hl-code">
</span><span class="hl-reserved">require_once</span><span class="hl-code"> </span><span class="hl-brackets">(</span><span class="hl-quotes">'</span><span class="hl-string">jpgraph/jpgraph.php</span><span class="hl-quotes">'</span><span class="hl-brackets">)</span><span class="hl-code">;
</span><span class="hl-reserved">require_once</span><span class="hl-code"> </span><span class="hl-brackets">(</span><span class="hl-quotes">'</span><span class="hl-string">jpgraph/jpgraph_pie.php</span><span class="hl-quotes">'</span><span class="hl-brackets">)</span><span class="hl-code">;
</span><span class="hl-var">$data</span><span class="hl-code"> = </span><span class="hl-reserved">array</span><span class="hl-brackets">(</span><span class="hl-number">40</span><span class="hl-code">,</span><span class="hl-number">60</span><span class="hl-code">,</span><span class="hl-number">21</span><span class="hl-code">,</span><span class="hl-number">33</span><span class="hl-brackets">)</span><span class="hl-code">;
</span><span class="hl-var">$graph</span><span class="hl-code"> = </span><span class="hl-reserved">new</span><span class="hl-code"> </span><span class="hl-identifier">PieGraph</span><span class="hl-brackets">(</span><span class="hl-number">300</span><span class="hl-code">,</span><span class="hl-number">200</span><span class="hl-brackets">)</span><span class="hl-code">;
</span><span class="hl-var">$graph</span><span class="hl-code">-&gt;</span><span class="hl-identifier">SetShadow</span><span class="hl-brackets">(</span><span class="hl-brackets">)</span><span class="hl-code">;
</span><span class="hl-var">$graph</span><span class="hl-code">-&gt;</span><span class="hl-identifier">title</span><span class="hl-code">-&gt;</span><span class="hl-identifier">Set</span><span class="hl-brackets">(</span><span class="hl-quotes">&quot;</span><span class="hl-string">A simple Pie plot</span><span class="hl-quotes">&quot;</span><span class="hl-brackets">)</span><span class="hl-code">;
</span><span class="hl-var">$p1</span><span class="hl-code"> = </span><span class="hl-reserved">new</span><span class="hl-code"> </span><span class="hl-identifier">PiePlot</span><span class="hl-brackets">(</span><span class="hl-var">$data</span><span class="hl-brackets">)</span><span class="hl-code">;
</span><span class="hl-var">$graph</span><span class="hl-code">-&gt;</span><span class="hl-identifier">Add</span><span class="hl-brackets">(</span><span class="hl-var">$p1</span><span class="hl-brackets">)</span><span class="hl-code">;
</span><span class="hl-var">$graph</span><span class="hl-code">-&gt;</span><span class="hl-identifier">Stroke</span><span class="hl-brackets">(</span><span class="hl-brackets">)</span><span class="hl-code">;
</span><span class="hl-inlinetags">?&gt;</span></pre></td></tr></table></div></div></div><p><br class="example-break"> </p><div class="figure"><a name="fig.example26"></a><p class="title"><b>Figure 16.8. A basic Pie graph <code class="uri"><a class="uri" href="example_src/example26.html" target="_top">(<code class="filename">example26.php</code>)</a></code> </b></p><div class="figure-contents"> <span class="inlinemediaobject"><img src="images/example26.png" alt="A basic Pie graph (example26.php)"></span> </div></div><p><br class="figure-break">
</p>
<p>There are a few things to note here</p>
<p>
</p><div class="itemizedlist"><ul class="itemizedlist" type="disc"><li class="listitem">
<p>By default all pie slices have the percentage shown just outside
the slice.</p>
</li><li class="listitem">
<p>The colors are automatically assigned to the slices.</p>
</li><li class="listitem">
<p>The pie have the edges marked by default</p>
</li><li class="listitem">
<p>The first slice start at 0 degrees (3 o'clock)</p>
</li></ul></div><p>
</p>
<p>It is possible to adjust most of the aspects of a pie graph. in addition to
the usual graph appearance adjustments discussed in <a class="xref" href="ch14s02.html" title="Specifying and formatting the overall displayed graph">Specifying and formatting the overall displayed graph</a> the following methods can be
used to adjust the appearance of the individual plots.</p>
<p>
</p><div class="itemizedlist"><ul class="itemizedlist" type="disc"><li class="listitem">
<p><code class="code">PiePlot::SetStartAngle($aAngle)</code></p>
<p>Change the angle for the first slice</p>
</li><li class="listitem">
<p><code class="code">PiePlot::ShowBorder($aFlg=true)</code></p>
<p>Show the border around and inside the pie</p>
</li><li class="listitem">
<p><code class="code">PiePlot::SetColor($aColor)</code></p>
<p>Specify the color of the border of the pie </p>
</li><li class="listitem">
<p><code class="code">PiePlot::SetSliceColors($aColor)</code></p>
<p>Specify the color of the slices</p>
</li><li class="listitem">
<p><code class="code">PiePlot::SetSize($aSize)</code></p>
<p>Set the size of the pie plot. This can be specified as either a
fraction of the minimum of the graph width and height or as a
absolute size in pixels.</p>
</li><li class="listitem">
<p><code class="code">PiePlot::SetCenter($aX, $aY)</code></p>
<p>Position the pie on the graph</p>
</li><li class="listitem">
<p><code class="code">PiePlot::value</code></p>
<p></p>
</li><li class="listitem">
<p><code class="code">PiePlot::SetLabels($aLabels,
$aLblPosAdj="auto")</code></p>
<p>Specify the labels for each pie slice</p>
</li><li class="listitem">
<p><code class="code">PiePlot::SetLabelType($aType)</code></p>
<p>By default the label is displayed as percentage. Using this method
it is possible to change the automatic label to show the absolute
value instead.</p>
</li></ul></div><p>
</p>
<p>In order to show a basic addition we add a legend to the pie graph. We do this
by using the <code class="code">SetLegends()</code> method. By adding the legends to the
previous example we get the result shown in <a class="xref" href="ch16.html#fig.example26.1" title="Figure 16.9. Adding a legend to a pie plot (example26.1.php)">Figure 16.9. Adding a legend to a pie plot <code class="uri"><a class="uri" href="example_src/example26.1.html" target="_top">(<code class="filename">example26.1.php</code>)</a></code> </a></p>
<p>
</p><div class="figure"><a name="fig.example26.1"></a><p class="title"><b>Figure 16.9. Adding a legend to a pie plot <code class="uri"><a class="uri" href="example_src/example26.1.html" target="_top">(<code class="filename">example26.1.php</code>)</a></code> </b></p><div class="figure-contents"> <span class="inlinemediaobject"><img src="images/example26.1.png" alt="Adding a legend to a pie plot (example26.1.php)"></span> </div></div><p><br class="figure-break">
</p>
<p>
</p><div class="note" title="Note" style="margin-left: 0.5in; margin-right: 0.5in;"><h3 class="title">Note</h3>
<p>In the figure above we also moved the center of the pie slightly to
the left to make more room for the legend box.</p>
</div><p>
</p>
<p>The text for the legends can also contain <code class="code">printf()</code> style format
strings to format a number. The number passed on into this string is either the
absolute value of the slice or the percentage value. The same formatting can
also be used to format the legend labels.</p>
<div class="sect3" title="Adding multiple pie plots to the same pie graph"><div class="titlepage"><div><div><h4 class="title"><a name="id2565214"></a>Adding multiple pie plots to the same pie graph</h4></div></div></div>
<p>This is done in complete analogy with the say multiple lines were added to
a line graph. The following code snippet shows the principle</p>
<p>
</p><div class="hl-main"><table class="hl-table" width="100%"><tr><td class="hl-gutter" align="right" valign="top"><pre>1
2
3
4
5
6
7
8
9
10
11
12
13
14
</pre></td><td class="hl-main" valign="top"><pre><span class="hl-inlinetags">&lt;?php</span><span class="hl-code">
</span><span class="hl-var">$piegraph</span><span class="hl-code"> = </span><span class="hl-reserved">new</span><span class="hl-code"> </span><span class="hl-identifier">PieGraph</span><span class="hl-brackets">(</span><span class="hl-var">$width</span><span class="hl-code">,</span><span class="hl-var">$height</span><span class="hl-brackets">)</span><span class="hl-code">;
</span><span class="hl-var">$p1</span><span class="hl-code"> = </span><span class="hl-reserved">new</span><span class="hl-code"> </span><span class="hl-identifier">PiePlot</span><span class="hl-brackets">(</span><span class="hl-var">$data1</span><span class="hl-brackets">)</span><span class="hl-code">;
</span><span class="hl-var">$p1</span><span class="hl-code">-&gt;</span><span class="hl-identifier">SetSize</span><span class="hl-brackets">(</span><span class="hl-number">0</span><span class="hl-number">.2</span><span class="hl-brackets">)</span><span class="hl-code">;
</span><span class="hl-var">$p1</span><span class="hl-code">-&gt;</span><span class="hl-identifier">SetCenter</span><span class="hl-brackets">(</span><span class="hl-number">0</span><span class="hl-number">.3</span><span class="hl-code">,</span><span class="hl-number">0</span><span class="hl-number">.6</span><span class="hl-brackets">)</span><span class="hl-code">;
</span><span class="hl-var">$p2</span><span class="hl-code"> = </span><span class="hl-reserved">new</span><span class="hl-code"> </span><span class="hl-identifier">PiePlot</span><span class="hl-brackets">(</span><span class="hl-var">$data2</span><span class="hl-brackets">)</span><span class="hl-code">;
</span><span class="hl-var">$p2</span><span class="hl-code">-&gt;</span><span class="hl-identifier">SetSize</span><span class="hl-brackets">(</span><span class="hl-number">0</span><span class="hl-number">.2</span><span class="hl-brackets">)</span><span class="hl-code">;
</span><span class="hl-var">$p2</span><span class="hl-code">-&gt;</span><span class="hl-identifier">SetCenter</span><span class="hl-brackets">(</span><span class="hl-number">0</span><span class="hl-number">.7</span><span class="hl-code">,</span><span class="hl-number">0</span><span class="hl-number">.6</span><span class="hl-brackets">)</span><span class="hl-code">;
</span><span class="hl-var">$piegraph</span><span class="hl-code">-&gt;</span><span class="hl-identifier">Add</span><span class="hl-brackets">(</span><span class="hl-var">$p1</span><span class="hl-brackets">)</span><span class="hl-code">;
</span><span class="hl-var">$piegraph</span><span class="hl-code">-&gt;</span><span class="hl-identifier">Add</span><span class="hl-brackets">(</span><span class="hl-var">$p2</span><span class="hl-brackets">)</span><span class="hl-code">;
</span><span class="hl-inlinetags">?&gt;</span></pre></td></tr></table></div><p>
</p>
<p>The positioning and sizing of the plots must be done manually. In the
following example we show an example where four pie plots are added to a
graph</p>
<p>
</p><div class="example"><a name="example.pieex3"></a><p class="title"><b>Example 16.2. Adding several pie plots to the same pie graph (<code class="filename">pieex3.php</code>) </b></p><div class="example-contents"> <div class="hl-main"><table class="hl-table" width="100%"><tr><td class="hl-gutter" align="right" valign="top"><pre>1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
</pre></td><td class="hl-main" valign="top"><pre><span class="hl-inlinetags">&lt;?php</span><span class="hl-code"> </span><span class="hl-comment">//</span><span class="hl-comment"> content=&quot;text/plain; charset=utf-8&quot;</span><span class="hl-comment"></span><span class="hl-code">
</span><span class="hl-reserved">require_once</span><span class="hl-code"> </span><span class="hl-brackets">(</span><span class="hl-quotes">'</span><span class="hl-string">jpgraph/jpgraph.php</span><span class="hl-quotes">'</span><span class="hl-brackets">)</span><span class="hl-code">;
</span><span class="hl-reserved">require_once</span><span class="hl-code"> </span><span class="hl-brackets">(</span><span class="hl-quotes">'</span><span class="hl-string">jpgraph/jpgraph_pie.php</span><span class="hl-quotes">'</span><span class="hl-brackets">)</span><span class="hl-code">;
</span><span class="hl-comment">//</span><span class="hl-comment"> Some data</span><span class="hl-comment"></span><span class="hl-code">
</span><span class="hl-var">$data</span><span class="hl-code"> = </span><span class="hl-reserved">array</span><span class="hl-brackets">(</span><span class="hl-number">40</span><span class="hl-code">,</span><span class="hl-number">21</span><span class="hl-code">,</span><span class="hl-number">17</span><span class="hl-code">,</span><span class="hl-number">14</span><span class="hl-code">,</span><span class="hl-number">23</span><span class="hl-brackets">)</span><span class="hl-code">;
</span><span class="hl-comment">//</span><span class="hl-comment"> Create the Pie Graph.</span><span class="hl-comment"></span><span class="hl-code">
</span><span class="hl-var">$graph</span><span class="hl-code"> = </span><span class="hl-reserved">new</span><span class="hl-code"> </span><span class="hl-identifier">PieGraph</span><span class="hl-brackets">(</span><span class="hl-number">350</span><span class="hl-code">,</span><span class="hl-number">300</span><span class="hl-brackets">)</span><span class="hl-code">;
</span><span class="hl-var">$graph</span><span class="hl-code">-&gt;</span><span class="hl-identifier">SetShadow</span><span class="hl-brackets">(</span><span class="hl-brackets">)</span><span class="hl-code">;
</span><span class="hl-comment">//</span><span class="hl-comment"> Set A title for the plot</span><span class="hl-comment"></span><span class="hl-code">
</span><span class="hl-var">$graph</span><span class="hl-code">-&gt;</span><span class="hl-identifier">title</span><span class="hl-code">-&gt;</span><span class="hl-identifier">Set</span><span class="hl-brackets">(</span><span class="hl-quotes">&quot;</span><span class="hl-string">Multiple - Pie plot</span><span class="hl-quotes">&quot;</span><span class="hl-brackets">)</span><span class="hl-code">;
</span><span class="hl-var">$graph</span><span class="hl-code">-&gt;</span><span class="hl-identifier">title</span><span class="hl-code">-&gt;</span><span class="hl-identifier">SetFont</span><span class="hl-brackets">(</span><span class="hl-identifier">FF_FONT1</span><span class="hl-code">,</span><span class="hl-identifier">FS_BOLD</span><span class="hl-brackets">)</span><span class="hl-code">;
</span><span class="hl-comment">//</span><span class="hl-comment"> Create plots</span><span class="hl-comment"></span><span class="hl-code">
</span><span class="hl-var">$size</span><span class="hl-code">=</span><span class="hl-number">0</span><span class="hl-number">.13</span><span class="hl-code">;
</span><span class="hl-var">$p1</span><span class="hl-code"> = </span><span class="hl-reserved">new</span><span class="hl-code"> </span><span class="hl-identifier">PiePlot</span><span class="hl-brackets">(</span><span class="hl-var">$data</span><span class="hl-brackets">)</span><span class="hl-code">;
</span><span class="hl-var">$p1</span><span class="hl-code">-&gt;</span><span class="hl-identifier">SetLegends</span><span class="hl-brackets">(</span><span class="hl-reserved">array</span><span class="hl-brackets">(</span><span class="hl-quotes">&quot;</span><span class="hl-string">Jan</span><span class="hl-quotes">&quot;</span><span class="hl-code">,</span><span class="hl-quotes">&quot;</span><span class="hl-string">Feb</span><span class="hl-quotes">&quot;</span><span class="hl-code">,</span><span class="hl-quotes">&quot;</span><span class="hl-string">Mar</span><span class="hl-quotes">&quot;</span><span class="hl-code">,</span><span class="hl-quotes">&quot;</span><span class="hl-string">Apr</span><span class="hl-quotes">&quot;</span><span class="hl-code">,</span><span class="hl-quotes">&quot;</span><span class="hl-string">May</span><span class="hl-quotes">&quot;</span><span class="hl-brackets">)</span><span class="hl-brackets">)</span><span class="hl-code">;
</span><span class="hl-var">$p1</span><span class="hl-code">-&gt;</span><span class="hl-identifier">SetSize</span><span class="hl-brackets">(</span><span class="hl-var">$size</span><span class="hl-brackets">)</span><span class="hl-code">;
</span><span class="hl-var">$p1</span><span class="hl-code">-&gt;</span><span class="hl-identifier">SetCenter</span><span class="hl-brackets">(</span><span class="hl-number">0</span><span class="hl-number">.25</span><span class="hl-code">,</span><span class="hl-number">0</span><span class="hl-number">.32</span><span class="hl-brackets">)</span><span class="hl-code">;
</span><span class="hl-var">$p1</span><span class="hl-code">-&gt;</span><span class="hl-identifier">value</span><span class="hl-code">-&gt;</span><span class="hl-identifier">SetFont</span><span class="hl-brackets">(</span><span class="hl-identifier">FF_FONT0</span><span class="hl-brackets">)</span><span class="hl-code">;
</span><span class="hl-var">$p1</span><span class="hl-code">-&gt;</span><span class="hl-identifier">title</span><span class="hl-code">-&gt;</span><span class="hl-identifier">Set</span><span class="hl-brackets">(</span><span class="hl-quotes">&quot;</span><span class="hl-string">2001</span><span class="hl-quotes">&quot;</span><span class="hl-brackets">)</span><span class="hl-code">;
</span><span class="hl-var">$p2</span><span class="hl-code"> = </span><span class="hl-reserved">new</span><span class="hl-code"> </span><span class="hl-identifier">PiePlot</span><span class="hl-brackets">(</span><span class="hl-var">$data</span><span class="hl-brackets">)</span><span class="hl-code">;
</span><span class="hl-var">$p2</span><span class="hl-code">-&gt;</span><span class="hl-identifier">SetSize</span><span class="hl-brackets">(</span><span class="hl-var">$size</span><span class="hl-brackets">)</span><span class="hl-code">;
</span><span class="hl-var">$p2</span><span class="hl-code">-&gt;</span><span class="hl-identifier">SetCenter</span><span class="hl-brackets">(</span><span class="hl-number">0</span><span class="hl-number">.65</span><span class="hl-code">,</span><span class="hl-number">0</span><span class="hl-number">.32</span><span class="hl-brackets">)</span><span class="hl-code">;
</span><span class="hl-var">$p2</span><span class="hl-code">-&gt;</span><span class="hl-identifier">value</span><span class="hl-code">-&gt;</span><span class="hl-identifier">SetFont</span><span class="hl-brackets">(</span><span class="hl-identifier">FF_FONT0</span><span class="hl-brackets">)</span><span class="hl-code">;
</span><span class="hl-var">$p2</span><span class="hl-code">-&gt;</span><span class="hl-identifier">title</span><span class="hl-code">-&gt;</span><span class="hl-identifier">Set</span><span class="hl-brackets">(</span><span class="hl-quotes">&quot;</span><span class="hl-string">2002</span><span class="hl-quotes">&quot;</span><span class="hl-brackets">)</span><span class="hl-code">;
</span><span class="hl-var">$p3</span><span class="hl-code"> = </span><span class="hl-reserved">new</span><span class="hl-code"> </span><span class="hl-identifier">PiePlot</span><span class="hl-brackets">(</span><span class="hl-var">$data</span><span class="hl-brackets">)</span><span class="hl-code">;
</span><span class="hl-var">$p3</span><span class="hl-code">-&gt;</span><span class="hl-identifier">SetSize</span><span class="hl-brackets">(</span><span class="hl-var">$size</span><span class="hl-brackets">)</span><span class="hl-code">;
</span><span class="hl-var">$p3</span><span class="hl-code">-&gt;</span><span class="hl-identifier">SetCenter</span><span class="hl-brackets">(</span><span class="hl-number">0</span><span class="hl-number">.25</span><span class="hl-code">,</span><span class="hl-number">0</span><span class="hl-number">.75</span><span class="hl-brackets">)</span><span class="hl-code">;
</span><span class="hl-var">$p3</span><span class="hl-code">-&gt;</span><span class="hl-identifier">value</span><span class="hl-code">-&gt;</span><span class="hl-identifier">SetFont</span><span class="hl-brackets">(</span><span class="hl-identifier">FF_FONT0</span><span class="hl-brackets">)</span><span class="hl-code">;
</span><span class="hl-var">$p3</span><span class="hl-code">-&gt;</span><span class="hl-identifier">title</span><span class="hl-code">-&gt;</span><span class="hl-identifier">Set</span><span class="hl-brackets">(</span><span class="hl-quotes">&quot;</span><span class="hl-string">2003</span><span class="hl-quotes">&quot;</span><span class="hl-brackets">)</span><span class="hl-code">;
</span><span class="hl-var">$p4</span><span class="hl-code"> = </span><span class="hl-reserved">new</span><span class="hl-code"> </span><span class="hl-identifier">PiePlot</span><span class="hl-brackets">(</span><span class="hl-var">$data</span><span class="hl-brackets">)</span><span class="hl-code">;
</span><span class="hl-var">$p4</span><span class="hl-code">-&gt;</span><span class="hl-identifier">SetSize</span><span class="hl-brackets">(</span><span class="hl-var">$size</span><span class="hl-brackets">)</span><span class="hl-code">;
</span><span class="hl-var">$p4</span><span class="hl-code">-&gt;</span><span class="hl-identifier">SetCenter</span><span class="hl-brackets">(</span><span class="hl-number">0</span><span class="hl-number">.65</span><span class="hl-code">,</span><span class="hl-number">0</span><span class="hl-number">.75</span><span class="hl-brackets">)</span><span class="hl-code">;
</span><span class="hl-var">$p4</span><span class="hl-code">-&gt;</span><span class="hl-identifier">value</span><span class="hl-code">-&gt;</span><span class="hl-identifier">SetFont</span><span class="hl-brackets">(</span><span class="hl-identifier">FF_FONT0</span><span class="hl-brackets">)</span><span class="hl-code">;
</span><span class="hl-var">$p4</span><span class="hl-code">-&gt;</span><span class="hl-identifier">title</span><span class="hl-code">-&gt;</span><span class="hl-identifier">Set</span><span class="hl-brackets">(</span><span class="hl-quotes">&quot;</span><span class="hl-string">2004</span><span class="hl-quotes">&quot;</span><span class="hl-brackets">)</span><span class="hl-code">;
</span><span class="hl-var">$graph</span><span class="hl-code">-&gt;</span><span class="hl-identifier">Add</span><span class="hl-brackets">(</span><span class="hl-var">$p1</span><span class="hl-brackets">)</span><span class="hl-code">;
</span><span class="hl-var">$graph</span><span class="hl-code">-&gt;</span><span class="hl-identifier">Add</span><span class="hl-brackets">(</span><span class="hl-var">$p2</span><span class="hl-brackets">)</span><span class="hl-code">;
</span><span class="hl-var">$graph</span><span class="hl-code">-&gt;</span><span class="hl-identifier">Add</span><span class="hl-brackets">(</span><span class="hl-var">$p3</span><span class="hl-brackets">)</span><span class="hl-code">;
</span><span class="hl-var">$graph</span><span class="hl-code">-&gt;</span><span class="hl-identifier">Add</span><span class="hl-brackets">(</span><span class="hl-var">$p4</span><span class="hl-brackets">)</span><span class="hl-code">;
</span><span class="hl-var">$graph</span><span class="hl-code">-&gt;</span><span class="hl-identifier">Stroke</span><span class="hl-brackets">(</span><span class="hl-brackets">)</span><span class="hl-code">;
</span><span class="hl-inlinetags">?&gt;</span></pre></td></tr></table></div></div></div><p><br class="example-break"> </p><div class="figure"><a name="fig.pieex3"></a><p class="title"><b>Figure 16.10. Adding several pie plots to the same pie graph <code class="uri"><a class="uri" href="example_src/pieex3.html" target="_top">(<code class="filename">pieex3.php</code>)</a></code> </b></p><div class="figure-contents"> <span class="inlinemediaobject"><img src="images/pieex3.png" alt="Adding several pie plots to the same pie graph (pieex3.php)"></span> </div></div><p><br class="figure-break">
</p>
</div>
<div class="sect3" title="Adding guide lines to Pie Plots"><div class="titlepage"><div><div><h4 class="title"><a name="id2565500"></a>Adding guide lines to Pie Plots</h4></div></div></div>
<p>For very busy Pie plots it can become too little space for the labels to
be printed just beside the pie slice. For this purpose it is possible to use
guide lines for the labels. The library will then draw a line from the
center edge of the slices to the label which will be positioned further out
from the Pie Plot.</p>
<p>There is one method that is primarily used to handle this</p>
<p>
</p><div class="itemizedlist"><ul class="itemizedlist" type="disc"><li class="listitem">
<p><code class="code">PiePlot::SetGuideLines($aFlg=true, $aCurved=true,
$aAlways=false)</code></p>
</li></ul></div><p>
</p>
<p>the simplest usage of this would be to add the following line to a
script</p>
<p>
</p><div class="hl-main"><table class="hl-table" width="100%"><tr><td class="hl-gutter" align="right" valign="top"><pre>1
</pre></td><td class="hl-main" valign="top"><pre><span class="hl-code">$pieplot-&gt;SetGuideLines();</span></pre></td></tr></table></div><p>
</p>
<p><a class="xref" href="ch16.html#fig.pielabelsex1" title="Figure 16.11. Adding guide lines to a pie labels (pielabelsex1.php)">Figure 16.11. Adding guide lines to a pie labels <code class="uri"><a class="uri" href="example_src/pielabelsex1.html" target="_top">(<code class="filename">pielabelsex1.php</code>)</a></code> </a> shows an example of this.</p>
<p>This basic use of guide lines is very similar as what is produced by other
programs, e.g. Excel. In addition to the above variant it is also possible
to instruct the library to line up the labels vertically in a way that we
think is easier to read. </p>
<p>This is achieved by specifying the second parameter to the
<code class="code">SetGuideLines()</code> to '<code class="code">false</code>' as </p>
<p>
</p><div class="hl-main"><table class="hl-table" width="100%"><tr><td class="hl-gutter" align="right" valign="top"><pre>1
</pre></td><td class="hl-main" valign="top"><pre><span class="hl-code">$pieplot-&gt;SetGuideLines( true , false );</span></pre></td></tr></table></div><p>
</p>
<p>The first parameter is to enable/disable the guide-lines. With the same
example as above this would then produce the image shown in <a class="xref" href="ch16.html#fig.pielabelsex2" title="Figure 16.12. Lining up guide lines vertically (pielabelsex2.php)">Figure 16.12. Lining up guide lines vertically <code class="uri"><a class="uri" href="example_src/pielabelsex2.html" target="_top">(<code class="filename">pielabelsex2.php</code>)</a></code> </a></p>
<p>
</p><div class="informaltable">
<table border="0"><colgroup><col class="c1"><col class="c2"></colgroup><tbody><tr><td>
<div class="figure"><a name="fig.pielabelsex1"></a><p class="title"><b>Figure 16.11. Adding guide lines to a pie labels <code class="uri"><a class="uri" href="example_src/pielabelsex1.html" target="_top">(<code class="filename">pielabelsex1.php</code>)</a></code> </b></p><div class="figure-contents"> <span class="inlinemediaobject"><img src="images/pielabelsex1.png" alt="Adding guide lines to a pie labels (pielabelsex1.php)"></span> </div></div><br class="figure-break">
</td><td>
<div class="figure"><a name="fig.pielabelsex2"></a><p class="title"><b>Figure 16.12. Lining up guide lines vertically <code class="uri"><a class="uri" href="example_src/pielabelsex2.html" target="_top">(<code class="filename">pielabelsex2.php</code>)</a></code> </b></p><div class="figure-contents"> <span class="inlinemediaobject"><img src="images/pielabelsex2.png" alt="Lining up guide lines vertically (pielabelsex2.php)"></span> </div></div><br class="figure-break">
</td></tr></tbody></table>
</div><p>
</p>
<p>It is also possible to configure the vertical distance between the labels.
By default the distance between the labels is roughly 40% of the labels font
height. By using the method <code class="code">PiePlot::SetGuideLinesAdjust()</code> it
is possible to specify a fractional value which is interpretated as the
distance between the bottom of one label to the bottom of the next. This
means that specifying a value of '1.0' the labels will have no space between
them and the bottom of one label will touch the top of another label. By
default this value is 1.4.</p>
<p>By increasing or decreasing this value it is possible to make the labels
become positioned more or less compact. In ?? this distance is reduced to
'1.1' and as can be seen this yields much more compact labeling.</p>
<p>
</p><div class="figure"><a name="fig.pielabelsex4"></a><p class="title"><b>Figure 16.13. Adjusting the distance between the labels for guide lines <code class="uri"><a class="uri" href="example_src/pielabelsex4.html" target="_top">(<code class="filename">pielabelsex4.php</code>)</a></code> </b></p><div class="figure-contents"> <span class="inlinemediaobject"><img src="images/pielabelsex4.png" alt="Adjusting the distance between the labels for guide lines (pielabelsex4.php)"></span> </div></div><p><br class="figure-break">
</p>
<p>
</p><div class="note" title="Note" style="margin-left: 0.5in; margin-right: 0.5in;"><h3 class="title">Note</h3>
<p>Guide lines is only available for 2D Pie plots.</p>
</div><p>
</p>
</div>
</div>
<div class="sect2" title="3D-Pie plots"><div class="titlepage"><div><div><h3 class="title"><a name="sec.pie-plots3d"></a>3D-Pie plots</h3></div></div></div>
<p>In order to create 3D Pie plots both the modules
"<code class="filename">jpgraph_pie.php</code>" and
"<code class="filename">jpgraph_pie3d.php</code>" must be included. </p>
<p>Creating 3D pie plots is as simple as creating normal 2D pie plots. Instead of
creating the plots as an instance of <code class="code">class PiePlot</code> the plots are
created as an instance of <code class="code">class PiePlot3D</code>
</p>
<p>If we take the plot in <a class="xref" href="ch16.html#fig.example26" title="Figure 16.8. A basic Pie graph (example26.php)">Figure 16.8. A basic Pie graph <code class="uri"><a class="uri" href="example_src/example26.html" target="_top">(<code class="filename">example26.php</code>)</a></code> </a> and replace the
creation of an instance of <code class="code">class PiePlot</code> with creating an instance
of <code class="code">class PiePlot3D</code> , i.e. replace</p>
<p>
</p><div class="hl-main"><table class="hl-table" width="100%"><tr><td class="hl-gutter" align="right" valign="top"><pre>1
</pre></td><td class="hl-main" valign="top"><pre><span class="hl-code">$p1 = new PiePlot($data);</span></pre></td></tr></table></div><p>
</p>
<p>with</p>
<p>
</p><div class="hl-main"><table class="hl-table" width="100%"><tr><td class="hl-gutter" align="right" valign="top"><pre>1
</pre></td><td class="hl-main" valign="top"><pre><span class="hl-code">$p1 = new PiePlot3D($data);</span></pre></td></tr></table></div><p>
</p>
<p>The result of this is shown in <a class="xref" href="ch16.html#fig.example27" title="Figure 16.14. A basic 3D pie plot (example27.php)">Figure 16.14. A basic 3D pie plot <code class="uri"><a class="uri" href="example_src/example27.html" target="_top">(<code class="filename">example27.php</code>)</a></code> </a></p>
<p>
</p><div class="figure"><a name="fig.example27"></a><p class="title"><b>Figure 16.14. A basic 3D pie plot <code class="uri"><a class="uri" href="example_src/example27.html" target="_top">(<code class="filename">example27.php</code>)</a></code> </b></p><div class="figure-contents"> <span class="inlinemediaobject"><img src="images/example27.png" alt="A basic 3D pie plot (example27.php)"></span> </div></div><p><br class="figure-break">
</p>
<p>3D Pie plots have the same possibilities as the normal pie plots with the
added twist of a 3:rd dimension. It is possible to adjust the perspective angle
with the method <code class="code">SetAngle()</code> So for example to make the pie more
"flat" the angle is made smaller angle. Setting the perspective angle to 20
degrees in the previous example will give the following result.</p>
<p>
</p><div class="figure"><a name="fig.example27.1"></a><p class="title"><b>Figure 16.15. Adjusting the perspective angle <code class="uri"><a class="uri" href="example_src/example27.1.html" target="_top">(<code class="filename">example27.1.php</code>)</a></code> </b></p><div class="figure-contents"> <span class="inlinemediaobject"><img src="images/example27.1.png" alt="Adjusting the perspective angle (example27.1.php)"></span> </div></div><p><br class="figure-break">
</p>
<p>To give a feel for the effect of adjusting the angle <a class="xref" href="ch16.html#fig.adjusting-pie3d-angle" title="Figure 16.16. Affect of adjusting the perspective angle for a 3D pie plot">Figure 16.16. Affect of adjusting the perspective angle for a 3D pie plot</a> below shows a number of different
angles,</p>
<p>
</p><div class="figure"><a name="fig.adjusting-pie3d-angle"></a><p class="title"><b>Figure 16.16. Affect of adjusting the perspective angle for a 3D pie plot</b></p><div class="figure-contents">
<div class="informaltable">
<table border="0"><colgroup><col class="c1"><col class="c2"><col class="c3"><col class="c4"></colgroup><tbody><tr><td align="center">
<p><span class="inlinemediaobject"><img src="images/img_mmpie3d_10.png" alt="Affect of adjusting the perspective angle for a 3D pie plot"></span></p>
<p>angle=10</p>
</td><td align="center">
<p><span class="inlinemediaobject"><img src="images/img_mmpie3d_20.png" alt="Affect of adjusting the perspective angle for a 3D pie plot"></span></p>
<p>angle=20</p>
</td><td align="center">
<p><span class="inlinemediaobject"><img src="images/img_mmpie3d_30.png" alt="Affect of adjusting the perspective angle for a 3D pie plot"></span></p>
<p>angle=30</p>
</td><td align="center">
<p><span class="inlinemediaobject"><img src="images/img_mmpie3d_40.png" alt="Affect of adjusting the perspective angle for a 3D pie plot"></span></p>
<p>angle=40</p>
</td></tr><tr><td align="center">
<p><span class="inlinemediaobject"><img src="images/img_mmpie3d_50.png" alt="Affect of adjusting the perspective angle for a 3D pie plot"></span></p>
<p>angle=50</p>
</td><td align="center">
<p><span class="inlinemediaobject"><img src="images/img_mmpie3d_60.png" alt="Affect of adjusting the perspective angle for a 3D pie plot"></span></p>
<p>angle=60</p>
</td><td align="center">
<p><span class="inlinemediaobject"><img src="images/img_mmpie3d_70.png" alt="Affect of adjusting the perspective angle for a 3D pie plot"></span></p>
<p>angle=70</p>
</td><td align="center">
<p><span class="inlinemediaobject"><img src="images/img_mmpie3d_80.png" alt="Affect of adjusting the perspective angle for a 3D pie plot"></span></p>
<p>angle=10</p>
</td></tr></tbody></table>
</div>
</div></div><p><br class="figure-break">
</p>
</div>
<div class="sect2" title="Ring plots"><div class="titlepage"><div><div><h3 class="title"><a name="sec.ring-plots"></a>Ring plots</h3></div></div></div>
<p>There are two versions of the 2D pie plots. The normal pie plot is created as
an instance of <code class="code">class PiePlot</code>. This variant is created as an
instance of <code class="code">class PiePlotC</code>.</p>
<p>This variant is an extension of the standard PiePlot in the sense that it also
have a filled circle in the center. An example of this is shown in ??</p>
<p>
</p><div class="figure"><a name="fig.piecex1"></a><p class="title"><b>Figure 16.17. A ring plot <code class="uri"><a class="uri" href="example_src/piecex1.html" target="_top">(<code class="filename">piecex1.php</code>)</a></code> </b></p><div class="figure-contents"> <span class="inlinemediaobject"><img src="images/piecex1.png" alt="A ring plot (piecex1.php)"></span> </div></div><p><br class="figure-break">
</p>
<p>Since the <code class="code">PiePlotC</code> is an extension to the basic pie plot all the
normal formatting for pie plots can also be done for a "ring" plot.</p>
<p>The additional formatting only concerns the filled middle circle. There are
options of adjusting size, fill color and all font properties. The following
methods are used for this</p>
<p>
</p><div class="itemizedlist"><ul class="itemizedlist" type="disc"><li class="listitem">
<p><code class="code">PiePlotC::SetMidColor() </code></p>
<p> Set fill color of mid circle</p>
</li><li class="listitem">
<p><code class="code">PiePlotC::SetMidSize()</code></p>
<p>Set size (fraction of radius)</p>
</li><li class="listitem">
<p><code class="code">PiePlotC::SetMidTitle()</code></p>
<p>Set title string (may be multi-lined)</p>
</li><li class="listitem">
<p><code class="code">PiePlotC::SetMid()</code></p>
<p> Set all parameters in a single method call</p>
</li></ul></div><p>
</p>
<p>In addition to the normal CSIM for PiePlot:s the center area is also a CSIM
hotspot. You specify the target CSIM with a call to </p>
<p>
</p><div class="itemizedlist"><ul class="itemizedlist" type="disc"><li class="listitem">
<p><code class="code">PiePlotC::SetMidCSIM()</code></p>
</li></ul></div><p>
</p>
<p>A more complex formatting of a ring plot is shown in <a class="xref" href="ch16.html#fig.piecex2" title="Figure 16.18. A ring graph with several formatting options adjusted (piecex2.php)">Figure 16.18. A ring graph with several formatting options adjusted <code class="uri"><a class="uri" href="example_src/piecex2.html" target="_top">(<code class="filename">piecex2.php</code>)</a></code> </a>. In this example we have:</p>
<p>
</p><div class="itemizedlist"><ul class="itemizedlist" type="disc"><li class="listitem">
<p>hidden the frame around the pie graph</p>
</li><li class="listitem">
<p>exploded all the slices</p>
</li><li class="listitem">
<p>added drop shadow to the individual slices (and the center filled
circle)</p>
</li><li class="listitem">
<p>specified individual multi line labels.</p>
</li><li class="listitem">
<p>changed the font for the title to a TTF font.</p>
</li></ul></div><p>
</p>
<p>
</p><div class="figure"><a name="fig.piecex2"></a><p class="title"><b>Figure 16.18. A ring graph with several formatting options adjusted <code class="uri"><a class="uri" href="example_src/piecex2.html" target="_top">(<code class="filename">piecex2.php</code>)</a></code> </b></p><div class="figure-contents"> <span class="inlinemediaobject"><img src="images/piecex2.png" alt="A ring graph with several formatting options adjusted (piecex2.php)"></span> </div></div><p><br class="figure-break">
</p>
</div>
<div class="sect2" title="Exploding pie slices"><div class="titlepage"><div><div><h3 class="title"><a name="id2566405"></a>Exploding pie slices</h3></div></div></div>
<p>One way to attract attention to some specific piece of information in a pie
chart is to "explode" one or more slices. Both 2D and 3D pies support exploding
one or several slices.</p>
<p>Exploding slices is accomplished by the methods </p>
<p>
</p><div class="itemizedlist"><ul class="itemizedlist" type="disc"><li class="listitem">
<p><code class="code">PiePlot::Explode($aExplodeArr)</code></p>
<p>This method takes an array of one or more slices index to
explode</p>
<p><code class="code">PiePlot::ExplodeAll($aRadius)</code></p>
<p>This explodes all slices in the pie</p>
<p><code class="code">PiePlot::ExplodeSlice($aSlice, $aRadius)</code></p>
<p>This is used to explode one specific slice</p>
</li></ul></div><p>
</p>
<p>To explode one slice the default "explode" radius the following line has to be
added</p>
<p>
</p><div class="hl-main"><table class="hl-table" width="100%"><tr><td class="hl-gutter" align="right" valign="top"><pre>1
</pre></td><td class="hl-main" valign="top"><pre><span class="hl-code">$pieplot-&gt;ExplodeSlice( 1 );</span></pre></td></tr></table></div><p>
</p>
<p>The above line would explode the second slice (slices are numbered from 0 and
upwards) the default amount. Doing this to the previous examples would result in
the following two figures</p>
<p>
</p><div class="informaltable">
<table border="0"><colgroup><col class="c1"><col class="c2"></colgroup><tbody><tr><td>
<div class="figure"><a name="fig.example27.2"></a><p class="title"><b>Figure 16.19. Exploding the second slice <code class="uri"><a class="uri" href="example_src/example27.2.html" target="_top">(<code class="filename">example27.2.php</code>)</a></code> </b></p><div class="figure-contents"> <span class="inlinemediaobject"><img src="images/example27.2.png" alt="Exploding the second slice (example27.2.php)"></span> </div></div><br class="figure-break">
</td><td>
<div class="figure"><a name="fig.example27.3"></a><p class="title"><b>Figure 16.20. Exploding the second slice <code class="uri"><a class="uri" href="example_src/example27.3.html" target="_top">(<code class="filename">example27.3.php</code>)</a></code> </b></p><div class="figure-contents"> <span class="inlinemediaobject"><img src="images/example27.3.png" alt="Exploding the second slice (example27.3.php)"></span> </div></div><br class="figure-break">
</td></tr></tbody></table>
</div><p>
</p>
</div>
<div class="sect2" title="Specifying and adjusting labels on pie plots"><div class="titlepage"><div><div><h3 class="title"><a name="id2566418"></a>Specifying and adjusting labels on pie plots</h3></div></div></div>
<p>By default the values shown just outside the pie for each slice are the
percentage value for each slice. If instead the absolute value should be
displayed the <code class="code">SetLabelType()</code> method must be called. To show
absolute values the following line must be added</p>
<p>
</p><div class="hl-main"><table class="hl-table" width="100%"><tr><td class="hl-gutter" align="right" valign="top"><pre>1
</pre></td><td class="hl-main" valign="top"><pre><span class="hl-code">$pieplot-&gt;SetLabelType(PIE_VALUE_ABS);</span></pre></td></tr></table></div><p>
</p>
<p>Furthermore is is possible to adjust the display value by either using a
<code class="code">printf()</code> style format string (using <code class="code">SetFormat()</code> )
or by providing a formatting function callback (using
<code class="code">PiePlot::SetFormatCallback()</code> ) for doing more advanced
formatting.</p>
<p>It is also possible to adjust the position of the labels by means of the
<code class="code">PiePlot::SetLabelPos()</code> method. The argument to this method is
either the fraction of the radius or the string '<code class="code">auto</code>'. In the
latter case the library automatically determines the best position. The
following example illustrates the effect of specifying the position to 0.5, i.e.
in the middle of the radius.</p>
<p>
</p><div class="figure"><a name="fig.pieex8"></a><p class="title"><b>Figure 16.21. Adjusting the position of the pie labels <code class="uri"><a class="uri" href="example_src/pieex8.html" target="_top">(<code class="filename">pieex8.php</code>)</a></code> </b></p><div class="figure-contents"> <span class="inlinemediaobject"><img src="images/pieex8.png" alt="Adjusting the position of the pie labels (pieex8.php)"></span> </div></div><p><br class="figure-break">
</p>
<p>If this formatting is not enough it is also possible to "manually" specify the
labels for each slice individually. </p>
<p>This is done by using the <code class="code">PiePlot::SetLabels()</code> method. This will
allow specifying individual text strings for each label. In each specification
it is possible to add a <code class="code">printf()</code> formatting specification for a
number. The number passed on will be either the absolute value for the slice or
the percentage value depending on what was specified in the call to
<code class="code">SetLabelType()</code>. </p>
<p>The <code class="code">SetLabels()</code> method can also take a second parameter, the
label position parameter. This is a shortcut to the
<code class="code">PiePlot::SetLabelPos()</code> as described above. By default the
position will be set to '<code class="code">auto</code>' if not explicitly specified.</p>
<div class="note" title="Note" style="margin-left: 0.5in; margin-right: 0.5in;"><h3 class="title">Note</h3>
<p>The alignment of the labels will be different depending on whether they
are inside or outside the pie. </p>
<p>When the label is positioned inside the plot the center of the strings
will be aligned with the center of the slice at the specified fraction of
the radius. When positioned is outside the pie plot the alignment will
depend on the angle to avoid that the labels inadvertently writes over the
pie.</p>
</div>
<p>When labels are specified with the <code class="code">PiePlot::SetLabels()</code> method it
is possible to also specify a format placeholder (in the normal style of
<code class="code">printf()</code> this placeholder will be replaced by the value of the
slice. For example a label specified as <code class="code">"The apple slice\n%.1f%%"</code>
would have the percentage value on the second row. The value will either be the
absolute or the percentage depending on the setting of the
<code class="code">SetLabelType()</code>.. The Pie chart in <a class="xref" href="ch16.html#fig.pielabelsex5" title="Figure 16.22. Pie chart with manually specified labels for each slice (pielabelsex5.php)">Figure 16.22. Pie chart with manually specified labels for each slice <code class="uri"><a class="uri" href="example_src/pielabelsex5.html" target="_top">(<code class="filename">pielabelsex5.php</code>)</a></code> </a> below shows an example where the slices
have a label just outside the perimeter of the pie. </p>
<p>
</p><div class="figure"><a name="fig.pielabelsex5"></a><p class="title"><b>Figure 16.22. Pie chart with manually specified labels for each slice <code class="uri"><a class="uri" href="example_src/pielabelsex5.html" target="_top">(<code class="filename">pielabelsex5.php</code>)</a></code> </b></p><div class="figure-contents"> <span class="inlinemediaobject"><img src="images/pielabelsex5.png" alt="Pie chart with manually specified labels for each slice (pielabelsex5.php)"></span> </div></div><p><br class="figure-break">
</p>
</div>
<div class="sect2" title="Adding drop shadows to the slices"><div class="titlepage"><div><div><h3 class="title"><a name="id2566836"></a>Adding drop shadows to the slices</h3></div></div></div>
<p>An additional visual enhancements can be made by adding a drop shadow to the
individual slices. This is accomplished by means of the </p>
<p>
</p><div class="itemizedlist"><ul class="itemizedlist" type="disc"><li class="listitem">
<p><code class="code">PiePlot::SetShadow() </code></p>
</li></ul></div><p>
</p>
<p>method. Adding a drop shadow is often more affective if the pie has one or
more slices exploded as shown in ??</p>
<p>
</p><div class="figure"><a name="fig.pieex9"></a><p class="title"><b>Figure 16.23. Adding a drop shadow to exploded pie <code class="uri"><a class="uri" href="example_src/pieex9.html" target="_top">(<code class="filename">pieex9.php</code>)</a></code> </b></p><div class="figure-contents"> <span class="inlinemediaobject"><img src="images/pieex9.png" alt="Adding a drop shadow to exploded pie (pieex9.php)"></span> </div></div><p><br class="figure-break">
</p>
</div>
<div class="sect2" title="Adding background images to Pie graphs"><div class="titlepage"><div><div><h3 class="title"><a name="sec.pie-image-background"></a>Adding background images to Pie graphs</h3></div></div></div>
<p>In the same way as every other graphs in the library it is possible to add a
background image to a Pie plot (see <a class="xref" href="ch14s15.html" title="Adding images and country flags to the background of the graph">Adding images and country flags to the background of the graph</a>). An example of this where we
have used multiple plots on a worldmap background is shown in <a class="xref" href="ch16.html#fig.piebkgex1" title="Figure 16.24. Pie plots with a background image (piebkgex1.php)">Figure 16.24. Pie plots with a background image <code class="uri"><a class="uri" href="example_src/piebkgex1.html" target="_top">(<code class="filename">piebkgex1.php</code>)</a></code> </a></p>
<p>
</p><div class="example"><a name="example.piebkgex1"></a><p class="title"><b>Example 16.3. Pie plots with a background image (<code class="filename">piebkgex1.php</code>) </b></p><div class="example-contents"> <div class="hl-main"><table class="hl-table" width="100%"><tr><td class="hl-gutter" align="right" valign="top"><pre>1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
</pre></td><td class="hl-main" valign="top"><pre><span class="hl-inlinetags">&lt;?php</span><span class="hl-code"> </span><span class="hl-comment">//</span><span class="hl-comment"> content=&quot;text/plain; charset=utf-8&quot;</span><span class="hl-comment"></span><span class="hl-code">
</span><span class="hl-reserved">require_once</span><span class="hl-code"> </span><span class="hl-brackets">(</span><span class="hl-quotes">'</span><span class="hl-string">jpgraph/jpgraph.php</span><span class="hl-quotes">'</span><span class="hl-brackets">)</span><span class="hl-code">;
</span><span class="hl-reserved">require_once</span><span class="hl-code"> </span><span class="hl-brackets">(</span><span class="hl-quotes">'</span><span class="hl-string">jpgraph/jpgraph_pie.php</span><span class="hl-quotes">'</span><span class="hl-brackets">)</span><span class="hl-code">;
</span><span class="hl-reserved">require_once</span><span class="hl-code"> </span><span class="hl-brackets">(</span><span class="hl-quotes">'</span><span class="hl-string">jpgraph/jpgraph_pie3d.php</span><span class="hl-quotes">'</span><span class="hl-brackets">)</span><span class="hl-code">;
</span><span class="hl-comment">//</span><span class="hl-comment"> Some data</span><span class="hl-comment"></span><span class="hl-code">
</span><span class="hl-var">$data</span><span class="hl-code"> = </span><span class="hl-reserved">array</span><span class="hl-brackets">(</span><span class="hl-code">
</span><span class="hl-reserved">array</span><span class="hl-brackets">(</span><span class="hl-number">80</span><span class="hl-code">,</span><span class="hl-number">18</span><span class="hl-code">,</span><span class="hl-number">15</span><span class="hl-code">,</span><span class="hl-number">17</span><span class="hl-brackets">)</span><span class="hl-code">,
</span><span class="hl-reserved">array</span><span class="hl-brackets">(</span><span class="hl-number">35</span><span class="hl-code">,</span><span class="hl-number">28</span><span class="hl-code">,</span><span class="hl-number">6</span><span class="hl-code">,</span><span class="hl-number">34</span><span class="hl-brackets">)</span><span class="hl-code">,
</span><span class="hl-reserved">array</span><span class="hl-brackets">(</span><span class="hl-number">10</span><span class="hl-code">,</span><span class="hl-number">28</span><span class="hl-code">,</span><span class="hl-number">10</span><span class="hl-code">,</span><span class="hl-number">5</span><span class="hl-brackets">)</span><span class="hl-code">,
</span><span class="hl-reserved">array</span><span class="hl-brackets">(</span><span class="hl-number">22</span><span class="hl-code">,</span><span class="hl-number">22</span><span class="hl-code">,</span><span class="hl-number">10</span><span class="hl-code">,</span><span class="hl-number">17</span><span class="hl-brackets">)</span><span class="hl-brackets">)</span><span class="hl-code">;
</span><span class="hl-var">$piepos</span><span class="hl-code"> = </span><span class="hl-reserved">array</span><span class="hl-brackets">(</span><span class="hl-number">0</span><span class="hl-number">.2</span><span class="hl-code">,</span><span class="hl-number">0</span><span class="hl-number">.4</span><span class="hl-code">,</span><span class="hl-number">0</span><span class="hl-number">.65</span><span class="hl-code">,</span><span class="hl-number">0</span><span class="hl-number">.28</span><span class="hl-code">,</span><span class="hl-number">0</span><span class="hl-number">.25</span><span class="hl-code">,</span><span class="hl-number">0</span><span class="hl-number">.75</span><span class="hl-code">,</span><span class="hl-number">0</span><span class="hl-number">.8</span><span class="hl-code">,</span><span class="hl-number">0</span><span class="hl-number">.75</span><span class="hl-brackets">)</span><span class="hl-code">;
</span><span class="hl-var">$titles</span><span class="hl-code"> = </span><span class="hl-reserved">array</span><span class="hl-brackets">(</span><span class="hl-quotes">'</span><span class="hl-string">USA</span><span class="hl-quotes">'</span><span class="hl-code">,</span><span class="hl-quotes">'</span><span class="hl-string">Sweden</span><span class="hl-quotes">'</span><span class="hl-code">,</span><span class="hl-quotes">'</span><span class="hl-string">South America</span><span class="hl-quotes">'</span><span class="hl-code">,</span><span class="hl-quotes">'</span><span class="hl-string">Australia</span><span class="hl-quotes">'</span><span class="hl-brackets">)</span><span class="hl-code">;
</span><span class="hl-var">$n</span><span class="hl-code"> = </span><span class="hl-identifier">count</span><span class="hl-brackets">(</span><span class="hl-var">$piepos</span><span class="hl-brackets">)</span><span class="hl-code">/</span><span class="hl-number">2</span><span class="hl-code">;
</span><span class="hl-comment">//</span><span class="hl-comment"> A new graph</span><span class="hl-comment"></span><span class="hl-code">
</span><span class="hl-var">$graph</span><span class="hl-code"> = </span><span class="hl-reserved">new</span><span class="hl-code"> </span><span class="hl-identifier">PieGraph</span><span class="hl-brackets">(</span><span class="hl-number">550</span><span class="hl-code">,</span><span class="hl-number">400</span><span class="hl-code">,</span><span class="hl-quotes">'</span><span class="hl-string">auto</span><span class="hl-quotes">'</span><span class="hl-brackets">)</span><span class="hl-code">;
</span><span class="hl-comment">//</span><span class="hl-comment"> Specify margins since we put the image in the plot area</span><span class="hl-comment"></span><span class="hl-code">
</span><span class="hl-var">$graph</span><span class="hl-code">-&gt;</span><span class="hl-identifier">SetMargin</span><span class="hl-brackets">(</span><span class="hl-number">1</span><span class="hl-code">,</span><span class="hl-number">1</span><span class="hl-code">,</span><span class="hl-number">40</span><span class="hl-code">,</span><span class="hl-number">1</span><span class="hl-brackets">)</span><span class="hl-code">;
</span><span class="hl-var">$graph</span><span class="hl-code">-&gt;</span><span class="hl-identifier">SetMarginColor</span><span class="hl-brackets">(</span><span class="hl-quotes">'</span><span class="hl-string">navy</span><span class="hl-quotes">'</span><span class="hl-brackets">)</span><span class="hl-code">;
</span><span class="hl-var">$graph</span><span class="hl-code">-&gt;</span><span class="hl-identifier">SetShadow</span><span class="hl-brackets">(</span><span class="hl-reserved">false</span><span class="hl-brackets">)</span><span class="hl-code">;
</span><span class="hl-comment">//</span><span class="hl-comment"> Setup background</span><span class="hl-comment"></span><span class="hl-code">
</span><span class="hl-var">$graph</span><span class="hl-code">-&gt;</span><span class="hl-identifier">SetBackgroundImage</span><span class="hl-brackets">(</span><span class="hl-quotes">'</span><span class="hl-string">worldmap1.jpg</span><span class="hl-quotes">'</span><span class="hl-code">,</span><span class="hl-identifier">BGIMG_FILLPLOT</span><span class="hl-brackets">)</span><span class="hl-code">;
</span><span class="hl-comment">//</span><span class="hl-comment"> Setup title</span><span class="hl-comment"></span><span class="hl-code">
</span><span class="hl-var">$graph</span><span class="hl-code">-&gt;</span><span class="hl-identifier">title</span><span class="hl-code">-&gt;</span><span class="hl-identifier">Set</span><span class="hl-brackets">(</span><span class="hl-quotes">&quot;</span><span class="hl-string">Pie plots with background image</span><span class="hl-quotes">&quot;</span><span class="hl-brackets">)</span><span class="hl-code">;
</span><span class="hl-var">$graph</span><span class="hl-code">-&gt;</span><span class="hl-identifier">title</span><span class="hl-code">-&gt;</span><span class="hl-identifier">SetFont</span><span class="hl-brackets">(</span><span class="hl-identifier">FF_ARIAL</span><span class="hl-code">,</span><span class="hl-identifier">FS_BOLD</span><span class="hl-code">,</span><span class="hl-number">20</span><span class="hl-brackets">)</span><span class="hl-code">;
</span><span class="hl-var">$graph</span><span class="hl-code">-&gt;</span><span class="hl-identifier">title</span><span class="hl-code">-&gt;</span><span class="hl-identifier">SetColor</span><span class="hl-brackets">(</span><span class="hl-quotes">'</span><span class="hl-string">white</span><span class="hl-quotes">'</span><span class="hl-brackets">)</span><span class="hl-code">;
</span><span class="hl-var">$p</span><span class="hl-code"> = </span><span class="hl-reserved">array</span><span class="hl-brackets">(</span><span class="hl-brackets">)</span><span class="hl-code">;
</span><span class="hl-comment">//</span><span class="hl-comment"> Create the plots</span><span class="hl-comment"></span><span class="hl-code">
</span><span class="hl-reserved">for</span><span class="hl-brackets">(</span><span class="hl-code"> </span><span class="hl-var">$i</span><span class="hl-code">=</span><span class="hl-number">0</span><span class="hl-code">; </span><span class="hl-var">$i</span><span class="hl-code"> &lt; </span><span class="hl-var">$n</span><span class="hl-code">; ++</span><span class="hl-var">$i</span><span class="hl-code"> </span><span class="hl-brackets">)</span><span class="hl-code"> </span><span class="hl-brackets">{</span><span class="hl-code">
</span><span class="hl-var">$d</span><span class="hl-code"> = </span><span class="hl-quotes">&quot;</span><span class="hl-string">data</span><span class="hl-var">$i</span><span class="hl-quotes">&quot;</span><span class="hl-code">;
</span><span class="hl-var">$p</span><span class="hl-brackets">[</span><span class="hl-brackets">]</span><span class="hl-code"> = </span><span class="hl-reserved">new</span><span class="hl-code"> </span><span class="hl-identifier">PiePlot3D</span><span class="hl-brackets">(</span><span class="hl-var">$data</span><span class="hl-brackets">[</span><span class="hl-var">$i</span><span class="hl-brackets">]</span><span class="hl-brackets">)</span><span class="hl-code">;
</span><span class="hl-brackets">}</span><span class="hl-code">
</span><span class="hl-comment">//</span><span class="hl-comment"> Position the four pies</span><span class="hl-comment"></span><span class="hl-code">
</span><span class="hl-reserved">for</span><span class="hl-brackets">(</span><span class="hl-code"> </span><span class="hl-var">$i</span><span class="hl-code">=</span><span class="hl-number">0</span><span class="hl-code">; </span><span class="hl-var">$i</span><span class="hl-code"> &lt; </span><span class="hl-var">$n</span><span class="hl-code">; ++</span><span class="hl-var">$i</span><span class="hl-code"> </span><span class="hl-brackets">)</span><span class="hl-code"> </span><span class="hl-brackets">{</span><span class="hl-code">
</span><span class="hl-var">$p</span><span class="hl-brackets">[</span><span class="hl-var">$i</span><span class="hl-brackets">]</span><span class="hl-code">-&gt;</span><span class="hl-identifier">SetCenter</span><span class="hl-brackets">(</span><span class="hl-var">$piepos</span><span class="hl-brackets">[</span><span class="hl-number">2</span><span class="hl-code">*</span><span class="hl-var">$i</span><span class="hl-brackets">]</span><span class="hl-code">,</span><span class="hl-var">$piepos</span><span class="hl-brackets">[</span><span class="hl-number">2</span><span class="hl-code">*</span><span class="hl-var">$i</span><span class="hl-code">+</span><span class="hl-number">1</span><span class="hl-brackets">]</span><span class="hl-brackets">)</span><span class="hl-code">;
</span><span class="hl-brackets">}</span><span class="hl-code">
</span><span class="hl-comment">//</span><span class="hl-comment"> Set the titles</span><span class="hl-comment"></span><span class="hl-code">
</span><span class="hl-reserved">for</span><span class="hl-brackets">(</span><span class="hl-code"> </span><span class="hl-var">$i</span><span class="hl-code">=</span><span class="hl-number">0</span><span class="hl-code">; </span><span class="hl-var">$i</span><span class="hl-code"> &lt; </span><span class="hl-var">$n</span><span class="hl-code">; ++</span><span class="hl-var">$i</span><span class="hl-code"> </span><span class="hl-brackets">)</span><span class="hl-code"> </span><span class="hl-brackets">{</span><span class="hl-code">
</span><span class="hl-var">$p</span><span class="hl-brackets">[</span><span class="hl-var">$i</span><span class="hl-brackets">]</span><span class="hl-code">-&gt;</span><span class="hl-identifier">title</span><span class="hl-code">-&gt;</span><span class="hl-identifier">Set</span><span class="hl-brackets">(</span><span class="hl-var">$titles</span><span class="hl-brackets">[</span><span class="hl-var">$i</span><span class="hl-brackets">]</span><span class="hl-brackets">)</span><span class="hl-code">;
</span><span class="hl-var">$p</span><span class="hl-brackets">[</span><span class="hl-var">$i</span><span class="hl-brackets">]</span><span class="hl-code">-&gt;</span><span class="hl-identifier">title</span><span class="hl-code">-&gt;</span><span class="hl-identifier">SetColor</span><span class="hl-brackets">(</span><span class="hl-quotes">'</span><span class="hl-string">white</span><span class="hl-quotes">'</span><span class="hl-brackets">)</span><span class="hl-code">;
</span><span class="hl-var">$p</span><span class="hl-brackets">[</span><span class="hl-var">$i</span><span class="hl-brackets">]</span><span class="hl-code">-&gt;</span><span class="hl-identifier">title</span><span class="hl-code">-&gt;</span><span class="hl-identifier">SetFont</span><span class="hl-brackets">(</span><span class="hl-identifier">FF_ARIAL</span><span class="hl-code">,</span><span class="hl-identifier">FS_BOLD</span><span class="hl-code">,</span><span class="hl-number">12</span><span class="hl-brackets">)</span><span class="hl-code">;
</span><span class="hl-brackets">}</span><span class="hl-code">
</span><span class="hl-comment">//</span><span class="hl-comment"> Label font and color setup</span><span class="hl-comment"></span><span class="hl-code">
</span><span class="hl-reserved">for</span><span class="hl-brackets">(</span><span class="hl-code"> </span><span class="hl-var">$i</span><span class="hl-code">=</span><span class="hl-number">0</span><span class="hl-code">; </span><span class="hl-var">$i</span><span class="hl-code"> &lt; </span><span class="hl-var">$n</span><span class="hl-code">; ++</span><span class="hl-var">$i</span><span class="hl-code"> </span><span class="hl-brackets">)</span><span class="hl-code"> </span><span class="hl-brackets">{</span><span class="hl-code">
</span><span class="hl-var">$p</span><span class="hl-brackets">[</span><span class="hl-var">$i</span><span class="hl-brackets">]</span><span class="hl-code">-&gt;</span><span class="hl-identifier">value</span><span class="hl-code">-&gt;</span><span class="hl-identifier">SetFont</span><span class="hl-brackets">(</span><span class="hl-identifier">FF_ARIAL</span><span class="hl-code">,</span><span class="hl-identifier">FS_BOLD</span><span class="hl-brackets">)</span><span class="hl-code">;
</span><span class="hl-var">$p</span><span class="hl-brackets">[</span><span class="hl-var">$i</span><span class="hl-brackets">]</span><span class="hl-code">-&gt;</span><span class="hl-identifier">value</span><span class="hl-code">-&gt;</span><span class="hl-identifier">SetColor</span><span class="hl-brackets">(</span><span class="hl-quotes">'</span><span class="hl-string">white</span><span class="hl-quotes">'</span><span class="hl-brackets">)</span><span class="hl-code">;
</span><span class="hl-brackets">}</span><span class="hl-code">
</span><span class="hl-comment">//</span><span class="hl-comment"> Show the percetages for each slice</span><span class="hl-comment"></span><span class="hl-code">
</span><span class="hl-reserved">for</span><span class="hl-brackets">(</span><span class="hl-code"> </span><span class="hl-var">$i</span><span class="hl-code">=</span><span class="hl-number">0</span><span class="hl-code">; </span><span class="hl-var">$i</span><span class="hl-code"> &lt; </span><span class="hl-var">$n</span><span class="hl-code">; ++</span><span class="hl-var">$i</span><span class="hl-code"> </span><span class="hl-brackets">)</span><span class="hl-code"> </span><span class="hl-brackets">{</span><span class="hl-code">
</span><span class="hl-var">$p</span><span class="hl-brackets">[</span><span class="hl-var">$i</span><span class="hl-brackets">]</span><span class="hl-code">-&gt;</span><span class="hl-identifier">value</span><span class="hl-code">-&gt;</span><span class="hl-identifier">Show</span><span class="hl-brackets">(</span><span class="hl-brackets">)</span><span class="hl-code">;
</span><span class="hl-brackets">}</span><span class="hl-code">
</span><span class="hl-comment">//</span><span class="hl-comment"> Label format</span><span class="hl-comment"></span><span class="hl-code">
</span><span class="hl-reserved">for</span><span class="hl-brackets">(</span><span class="hl-code"> </span><span class="hl-var">$i</span><span class="hl-code">=</span><span class="hl-number">0</span><span class="hl-code">; </span><span class="hl-var">$i</span><span class="hl-code"> &lt; </span><span class="hl-var">$n</span><span class="hl-code">; ++</span><span class="hl-var">$i</span><span class="hl-code"> </span><span class="hl-brackets">)</span><span class="hl-code"> </span><span class="hl-brackets">{</span><span class="hl-code">
</span><span class="hl-var">$p</span><span class="hl-brackets">[</span><span class="hl-var">$i</span><span class="hl-brackets">]</span><span class="hl-code">-&gt;</span><span class="hl-identifier">value</span><span class="hl-code">-&gt;</span><span class="hl-identifier">SetFormat</span><span class="hl-brackets">(</span><span class="hl-quotes">&quot;</span><span class="hl-string">%01.1f%%</span><span class="hl-quotes">&quot;</span><span class="hl-brackets">)</span><span class="hl-code">;
</span><span class="hl-brackets">}</span><span class="hl-code">
</span><span class="hl-comment">//</span><span class="hl-comment"> Size of pie in fraction of the width of the graph</span><span class="hl-comment"></span><span class="hl-code">
</span><span class="hl-reserved">for</span><span class="hl-brackets">(</span><span class="hl-code"> </span><span class="hl-var">$i</span><span class="hl-code">=</span><span class="hl-number">0</span><span class="hl-code">; </span><span class="hl-var">$i</span><span class="hl-code"> &lt; </span><span class="hl-var">$n</span><span class="hl-code">; ++</span><span class="hl-var">$i</span><span class="hl-code"> </span><span class="hl-brackets">)</span><span class="hl-code"> </span><span class="hl-brackets">{</span><span class="hl-code">
</span><span class="hl-var">$p</span><span class="hl-brackets">[</span><span class="hl-var">$i</span><span class="hl-brackets">]</span><span class="hl-code">-&gt;</span><span class="hl-identifier">SetSize</span><span class="hl-brackets">(</span><span class="hl-number">0</span><span class="hl-number">.15</span><span class="hl-brackets">)</span><span class="hl-code">;
</span><span class="hl-brackets">}</span><span class="hl-code">
</span><span class="hl-comment">//</span><span class="hl-comment"> Format the border around each slice</span><span class="hl-comment"></span><span class="hl-code">
</span><span class="hl-reserved">for</span><span class="hl-brackets">(</span><span class="hl-code"> </span><span class="hl-var">$i</span><span class="hl-code">=</span><span class="hl-number">0</span><span class="hl-code">; </span><span class="hl-var">$i</span><span class="hl-code"> &lt; </span><span class="hl-var">$n</span><span class="hl-code">; ++</span><span class="hl-var">$i</span><span class="hl-code"> </span><span class="hl-brackets">)</span><span class="hl-code"> </span><span class="hl-brackets">{</span><span class="hl-code">
</span><span class="hl-var">$p</span><span class="hl-brackets">[</span><span class="hl-var">$i</span><span class="hl-brackets">]</span><span class="hl-code">-&gt;</span><span class="hl-identifier">SetEdge</span><span class="hl-brackets">(</span><span class="hl-reserved">false</span><span class="hl-brackets">)</span><span class="hl-code">;
</span><span class="hl-var">$p</span><span class="hl-brackets">[</span><span class="hl-var">$i</span><span class="hl-brackets">]</span><span class="hl-code">-&gt;</span><span class="hl-identifier">ExplodeSlice</span><span class="hl-brackets">(</span><span class="hl-number">1</span><span class="hl-brackets">)</span><span class="hl-code">;
</span><span class="hl-brackets">}</span><span class="hl-code">
</span><span class="hl-comment">//</span><span class="hl-comment"> Use one legend for the whole graph</span><span class="hl-comment"></span><span class="hl-code">
</span><span class="hl-var">$p</span><span class="hl-brackets">[</span><span class="hl-number">0</span><span class="hl-brackets">]</span><span class="hl-code">-&gt;</span><span class="hl-identifier">SetLegends</span><span class="hl-brackets">(</span><span class="hl-reserved">array</span><span class="hl-brackets">(</span><span class="hl-quotes">&quot;</span><span class="hl-string">May</span><span class="hl-quotes">&quot;</span><span class="hl-code">,</span><span class="hl-quotes">&quot;</span><span class="hl-string">June</span><span class="hl-quotes">&quot;</span><span class="hl-code">,</span><span class="hl-quotes">&quot;</span><span class="hl-string">July</span><span class="hl-quotes">&quot;</span><span class="hl-code">,</span><span class="hl-quotes">&quot;</span><span class="hl-string">Aug</span><span class="hl-quotes">&quot;</span><span class="hl-brackets">)</span><span class="hl-brackets">)</span><span class="hl-code">;
</span><span class="hl-var">$graph</span><span class="hl-code">-&gt;</span><span class="hl-identifier">legend</span><span class="hl-code">-&gt;</span><span class="hl-identifier">Pos</span><span class="hl-brackets">(</span><span class="hl-number">0</span><span class="hl-number">.05</span><span class="hl-code">,</span><span class="hl-number">0</span><span class="hl-number">.35</span><span class="hl-brackets">)</span><span class="hl-code">;
</span><span class="hl-var">$graph</span><span class="hl-code">-&gt;</span><span class="hl-identifier">legend</span><span class="hl-code">-&gt;</span><span class="hl-identifier">SetShadow</span><span class="hl-brackets">(</span><span class="hl-reserved">false</span><span class="hl-brackets">)</span><span class="hl-code">;
</span><span class="hl-reserved">for</span><span class="hl-brackets">(</span><span class="hl-code"> </span><span class="hl-var">$i</span><span class="hl-code">=</span><span class="hl-number">0</span><span class="hl-code">; </span><span class="hl-var">$i</span><span class="hl-code"> &lt; </span><span class="hl-var">$n</span><span class="hl-code">; ++</span><span class="hl-var">$i</span><span class="hl-code"> </span><span class="hl-brackets">)</span><span class="hl-code"> </span><span class="hl-brackets">{</span><span class="hl-code">
</span><span class="hl-var">$graph</span><span class="hl-code">-&gt;</span><span class="hl-identifier">Add</span><span class="hl-brackets">(</span><span class="hl-var">$p</span><span class="hl-brackets">[</span><span class="hl-var">$i</span><span class="hl-brackets">]</span><span class="hl-brackets">)</span><span class="hl-code">;
</span><span class="hl-brackets">}</span><span class="hl-code">
</span><span class="hl-var">$graph</span><span class="hl-code">-&gt;</span><span class="hl-identifier">Stroke</span><span class="hl-brackets">(</span><span class="hl-brackets">)</span><span class="hl-code">;
</span><span class="hl-inlinetags">?&gt;</span></pre></td></tr></table></div></div></div><p><br class="example-break"> </p><div class="figure"><a name="fig.piebkgex1"></a><p class="title"><b>Figure 16.24. Pie plots with a background image <code class="uri"><a class="uri" href="example_src/piebkgex1.html" target="_top">(<code class="filename">piebkgex1.php</code>)</a></code> </b></p><div class="figure-contents"> <span class="inlinemediaobject"><img src="images/piebkgex1.png" alt="Pie plots with a background image (piebkgex1.php)"></span> </div></div><p><br class="figure-break">
</p>
</div>
<div class="sect2" title="Specifying slice colors and using themes"><div class="titlepage"><div><div><h3 class="title"><a name="sec.pie-color-themes"></a>Specifying slice colors and using themes</h3></div></div></div>
<p>In addition to manually specifying the colors of each individual pie slice it
is possible to specify a color "theme" to be used. A color theme is nothing more
than a group of predefined colors that will be used for the slices. Each theme
is referred to by it's name (as a string) as argument for the method</p>
<p>
</p><div class="itemizedlist"><ul class="itemizedlist" type="disc"><li class="listitem">
<p><code class="code">PiePlot::SetTheme($aTheme)</code></p>
</li></ul></div><p>
</p>
<p>By default the library offers four different color themes listed below with a
small example graph using that particular theme. </p>
<p>
</p><div class="orderedlist"><ol class="orderedlist" type="1"><li class="listitem">
<p>"earth" colors</p>
<p>
</p><div class="figure"><a name="fig.example28.1"></a><p class="title"><b>Figure 16.25.  <code class="uri"><a class="uri" href="example_src/example28.1.html" target="_top">(<code class="filename">example28.1.php</code>)</a></code> </b></p><div class="figure-contents"> <span class="inlinemediaobject"><img src="images/example28.1.png" alt="(example28.1.php)"></span> </div></div><p><br class="figure-break">
</p>
</li><li class="listitem">
<p>"pastel" colors</p>
<p>
</p><div class="figure"><a name="fig.example28.2"></a><p class="title"><b>Figure 16.26.  <code class="uri"><a class="uri" href="example_src/example28.2.html" target="_top">(<code class="filename">example28.2.php</code>)</a></code> </b></p><div class="figure-contents"> <span class="inlinemediaobject"><img src="images/example28.2.png" alt="(example28.2.php)"></span> </div></div><p><br class="figure-break">
</p>
</li><li class="listitem">
<p>"sand" colors</p>
<p>
</p><div class="figure"><a name="fig.example28"></a><p class="title"><b>Figure 16.27.  <code class="uri"><a class="uri" href="example_src/example28.html" target="_top">(<code class="filename">example28.php</code>)</a></code> </b></p><div class="figure-contents"> <span class="inlinemediaobject"><img src="images/example28.png" alt="(example28.php)"></span> </div></div><p><br class="figure-break">
</p>
</li><li class="listitem">
<p>"water" colors</p>
<p>
</p><div class="figure"><a name="fig.example28.3"></a><p class="title"><b>Figure 16.28.  <code class="uri"><a class="uri" href="example_src/example28.3.html" target="_top">(<code class="filename">example28.3.php</code>)</a></code> </b></p><div class="figure-contents"> <span class="inlinemediaobject"><img src="images/example28.3.png" alt="(example28.3.php)"></span> </div></div><p><br class="figure-break">
</p>
</li></ol></div><p>
</p>
<p>Color chart for each available theme is shown below.</p>
<div class="figure"><a name="id2567222"></a><p class="title"><b>Figure 16.29. Earth theme</b></p><div class="figure-contents">
<div class="mediaobject"><img src="images/pie_theme_earth.png" alt="Earth theme"></div>
</div></div><br class="figure-break">
<div class="figure"><a name="id2567233"></a><p class="title"><b>Figure 16.30. Pastel theme</b></p><div class="figure-contents">
<div class="mediaobject"><img src="images/pie_theme_pastel.png" alt="Pastel theme"></div>
</div></div><br class="figure-break">
<div class="figure"><a name="id2567250"></a><p class="title"><b>Figure 16.31. Sand theme</b></p><div class="figure-contents">
<div class="mediaobject"><img src="images/pie_theme_sand.png" alt="Sand theme"></div>
</div></div><br class="figure-break">
<div class="figure"><a name="id2567268"></a><p class="title"><b>Figure 16.32. Water theme</b></p><div class="figure-contents">
<div class="mediaobject"><img src="images/pie_theme_water.png" alt="Water theme"></div>
</div></div><br class="figure-break">
</div>
</div>
</div><div class="navfooter"><hr><table width="100%" summary="Navigation footer"><tr><td width="40%" align="left"> </td><td width="20%" align="center"><a accesskey="u" href="pt04.html">Up</a></td><td width="40%" align="right"> </td></tr><tr><td width="40%" align="left" valign="top"> </td><td width="20%" align="center"><a accesskey="h" href="index.html">Home</a></td><td width="40%" align="right" valign="top"> </td></tr></table></div></body></html>