Blame | Last modification | View Log | RSS feed
<?xml version="1.0" encoding="ISO-8859-1" standalone="no"?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"><html xmlns="http://www.w3.org/1999/xhtml"><head><meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1" /><title>5.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>
This example shows the use of <a class="xref" href="SetPieStartAngle.html" title="SetPieStartAngle"><span class="refentrytitle">SetPieStartAngle</span></a> and
<a class="xref" href="SetPieDirection.html" title="SetPieDirection"><span class="refentrytitle">SetPieDirection</span></a> to set the starting angle for the first
segment in a pie chart, and the direction of the segments (clockwise or
counter-clockwise).
Note that the ability to change the starting angle and segment direction
was added to PHPlot-6.0.0.
</p><p>
In each of the 8 plots, the pie segments are numbered from 0, with segment 0
being the first entry in the data array.
The upper-left plot represents the default, and the only available
option before PHPlot-6.0.0, with counter-clockwise pie segments starting
at 0 degrees.
</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
# PHPlot Example: Pie chart with varying start angle and direction
# Note: This requires PHPlot-6.0.0 or higher.
require_once 'phplot.php';
$pie_slices = 6;
$base_angle = 0;
# This callback is used to label each plot with a title.
# The x_title font is set below and used here.
function draw_plot_title($img, $args)
{
list($plot, $x, $y, $title) = $args;
$text_color = imagecolorresolve($img, 0, 0, 0);
$plot->DrawText('x_title', 0, $x, $y, $text_color, $title, 'center', 'top');
}
# Produce one plot tile
function draw_plot($plot, $start_angle, $direction, $xbase, $ybase)
{
$plot->SetPieStartAngle($start_angle);
$plot->SetPieDirection($direction);
$plot->SetPlotAreaPixels($xbase, $ybase, $xbase + 200, $ybase + 200);
$title = "Start @{$start_angle}d $direction";
$plot->SetCallback('draw_all', 'draw_plot_title',
array($plot, $xbase + 100, $ybase + 200, $title));
$plot->DrawGraph();
}
# Make a data array with equal-size slices:
$data = array_fill(0, $pie_slices, array('', 1));
$plot = new PHPlot(800, 600);
$plot->SetDataValues($data);
$plot->SetDataType('text-data-single');
$plot->SetPlotType('pie');
$plot->SetShading(0);
$plot->SetImageBorderType('plain');
$plot->SetPrintImage(False);
$plot->SetTitle("Pie Chart - Vary Start Angle and Direction\n"
. "(CW = Clockwise, CCW = Counter-clockwise)");
# Configure pie labels: Show sector index, inside the pie, in a large font.
$plot->SetPieLabelType('index');
$plot->SetLabelScalePosition(0.25);
# Use the default TrueType font at 36 points.
$plot->SetFontTTF('generic', '', 36);
# This font is used by the callback to label each plot:
# Use the default TrueType font at 16 points.
$plot->SetFontTTF('x_title', '', 16); // Use the default TTF font at 16 pts
# Draw the plot tiles:
draw_plot($plot, $base_angle + 0, 'CCW', 0, 50);
draw_plot($plot, $base_angle + 90, 'CCW', 200, 50);
draw_plot($plot, $base_angle + 180, 'CCW', 400, 50);
draw_plot($plot, $base_angle + 270, 'CCW', 600, 50);
draw_plot($plot, $base_angle + 0, 'CW', 0, 300);
draw_plot($plot, $base_angle + 90, 'CW', 200, 300);
draw_plot($plot, $base_angle + 180, 'CW', 400, 300);
draw_plot($plot, $base_angle + 270, 'CW', 600, 300);
# Done:
$plot->PrintImage();
</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>