98 |
- |
1 |
<?xml version="1.0" encoding="ISO-8859-1" standalone="no"?>
|
|
|
2 |
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"><html xmlns="http://www.w3.org/1999/xhtml"><head><meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1" /><title>5.47. Example - Pie Chart Start Angle and Direction</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-imagemap-nonembed.html" title="5.46. Example - Image Map and Non-embedded Plot Image" /><link rel="next" href="ex-horizlinepts.html" title="5.48. Example - Horizontal Linepoints Plot with Data Value Labels and Lines" /></head><body><div class="navheader"><table width="100%" summary="Navigation header"><tr><th colspan="3" align="center">5.47. Example - Pie Chart Start Angle and Direction</th></tr><tr><td width="20%" align="left"><a accesskey="p" href="ex-imagemap-nonembed.html">Prev</a> </td><th width="60%" align="center">Chapter 5. PHPlot Examples</th><td width="20%" align="right"> <a accesskey="n" href="ex-horizlinepts.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-pieangle"></a>5.47. Example - Pie Chart Start Angle and Direction</h2></div></div></div><p>
|
|
|
3 |
This example shows the use of <a class="xref" href="SetPieStartAngle.html" title="SetPieStartAngle"><span class="refentrytitle">SetPieStartAngle</span></a> and
|
|
|
4 |
<a class="xref" href="SetPieDirection.html" title="SetPieDirection"><span class="refentrytitle">SetPieDirection</span></a> to set the starting angle for the first
|
|
|
5 |
segment in a pie chart, and the direction of the segments (clockwise or
|
|
|
6 |
counter-clockwise).
|
|
|
7 |
Note that the ability to change the starting angle and segment direction
|
|
|
8 |
was added to PHPlot-6.0.0.
|
|
|
9 |
</p><p>
|
|
|
10 |
In each of the 8 plots, the pie segments are numbered from 0, with segment 0
|
|
|
11 |
being the first entry in the data array.
|
|
|
12 |
The upper-left plot represents the default, and the only available
|
|
|
13 |
option before PHPlot-6.0.0, with counter-clockwise pie segments starting
|
|
|
14 |
at 0 degrees.
|
|
|
15 |
</p><div class="example"><a id="example-pieangle"></a><p class="title"><strong>Example 5.47. Pie Chart Start Angle and Direction</strong></p><div class="example-contents"><div class="informalfigure"><div class="mediaobject"><img src="examples/pieangle.png" alt="Pie Chart Start Angle and Direction Example" /></div></div><pre class="programlisting"><?php
|
|
|
16 |
# PHPlot Example: Pie chart with varying start angle and direction
|
|
|
17 |
# Note: This requires PHPlot-6.0.0 or higher.
|
|
|
18 |
require_once 'phplot.php';
|
|
|
19 |
|
|
|
20 |
$pie_slices = 6;
|
|
|
21 |
$base_angle = 0;
|
|
|
22 |
|
|
|
23 |
# This callback is used to label each plot with a title.
|
|
|
24 |
# The x_title font is set below and used here.
|
|
|
25 |
function draw_plot_title($img, $args)
|
|
|
26 |
{
|
|
|
27 |
list($plot, $x, $y, $title) = $args;
|
|
|
28 |
$text_color = imagecolorresolve($img, 0, 0, 0);
|
|
|
29 |
$plot->DrawText('x_title', 0, $x, $y, $text_color, $title, 'center', 'top');
|
|
|
30 |
}
|
|
|
31 |
|
|
|
32 |
# Produce one plot tile
|
|
|
33 |
function draw_plot($plot, $start_angle, $direction, $xbase, $ybase)
|
|
|
34 |
{
|
|
|
35 |
$plot->SetPieStartAngle($start_angle);
|
|
|
36 |
$plot->SetPieDirection($direction);
|
|
|
37 |
$plot->SetPlotAreaPixels($xbase, $ybase, $xbase + 200, $ybase + 200);
|
|
|
38 |
$title = "Start @{$start_angle}d $direction";
|
|
|
39 |
$plot->SetCallback('draw_all', 'draw_plot_title',
|
|
|
40 |
array($plot, $xbase + 100, $ybase + 200, $title));
|
|
|
41 |
$plot->DrawGraph();
|
|
|
42 |
}
|
|
|
43 |
|
|
|
44 |
# Make a data array with equal-size slices:
|
|
|
45 |
$data = array_fill(0, $pie_slices, array('', 1));
|
|
|
46 |
|
|
|
47 |
$plot = new PHPlot(800, 600);
|
|
|
48 |
$plot->SetDataValues($data);
|
|
|
49 |
$plot->SetDataType('text-data-single');
|
|
|
50 |
$plot->SetPlotType('pie');
|
|
|
51 |
$plot->SetShading(0);
|
|
|
52 |
$plot->SetImageBorderType('plain');
|
|
|
53 |
$plot->SetPrintImage(False);
|
|
|
54 |
$plot->SetTitle("Pie Chart - Vary Start Angle and Direction\n"
|
|
|
55 |
. "(CW = Clockwise, CCW = Counter-clockwise)");
|
|
|
56 |
|
|
|
57 |
# Configure pie labels: Show sector index, inside the pie, in a large font.
|
|
|
58 |
$plot->SetPieLabelType('index');
|
|
|
59 |
$plot->SetLabelScalePosition(0.25);
|
|
|
60 |
# Use the default TrueType font at 36 points.
|
|
|
61 |
$plot->SetFontTTF('generic', '', 36);
|
|
|
62 |
|
|
|
63 |
# This font is used by the callback to label each plot:
|
|
|
64 |
# Use the default TrueType font at 16 points.
|
|
|
65 |
$plot->SetFontTTF('x_title', '', 16); // Use the default TTF font at 16 pts
|
|
|
66 |
|
|
|
67 |
# Draw the plot tiles:
|
|
|
68 |
draw_plot($plot, $base_angle + 0, 'CCW', 0, 50);
|
|
|
69 |
draw_plot($plot, $base_angle + 90, 'CCW', 200, 50);
|
|
|
70 |
draw_plot($plot, $base_angle + 180, 'CCW', 400, 50);
|
|
|
71 |
draw_plot($plot, $base_angle + 270, 'CCW', 600, 50);
|
|
|
72 |
|
|
|
73 |
draw_plot($plot, $base_angle + 0, 'CW', 0, 300);
|
|
|
74 |
draw_plot($plot, $base_angle + 90, 'CW', 200, 300);
|
|
|
75 |
draw_plot($plot, $base_angle + 180, 'CW', 400, 300);
|
|
|
76 |
draw_plot($plot, $base_angle + 270, 'CW', 600, 300);
|
|
|
77 |
|
|
|
78 |
# Done:
|
|
|
79 |
$plot->PrintImage();
|
|
|
80 |
</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-imagemap-nonembed.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-horizlinepts.html">Next</a></td></tr><tr><td width="40%" align="left" valign="top">5.46. Example - Image Map and Non-embedded Plot Image </td><td width="20%" align="center"><a accesskey="h" href="index.html">Home</a></td><td width="40%" align="right" valign="top"> 5.48. Example - Horizontal Linepoints Plot with Data Value Labels and Lines</td></tr></table></div></body></html>
|