CLASS PiePlot
(Defined in: jpgraph_pie.php : 25) Class usage and Overview
Creates a new Pie plot from the supplied data.
By default the value (if enabled through the $pie->label->show() ) close to each slice will have a label corresponding to the percentage of that slice.
Each plot may have an arbitrary title which can be accessed through the ?title? property in the PiePlot class. The title will be automatically centred on top of the PiePlot clear of any possible labels. To set the title use the Set() method , i.e. $plot->title->Set(?MyTitle?).
To format the slice labels use the SetFormat() method of the value class.
See also related classes:
PieGraph and PiePlot3D
Class Methods
function Explode($aExplodeArr)
Explode one or more slices as specified radius.
Argument | Default | Description |
$aExplodeArr
| | Explode specification |
Description
To emphasise a specific slice it can be exploded, i.e moved out fro the center of the pie plot. This method will allow you to specify what slices and to waht radius you want them exploded.
If you only want to explode a single slice you could also use the ExplodeSlice() method.
See also
PiePlot::ExplodeSlice
//To explode slice 0,2 to radius 100 you would call
$pieplot->Explode(array(100,0,100));
function ExplodeAll($radius)
Explode all slices a specified amount
Argument | Default | Description |
$radius
|
20
| Explode radius |
Description
Explode all slices a specified amount. If no radius is specified it will default to 20 pixels.
See also
PiePlot::ExplodeSlice and PiePlot::Explode
$p1->ExplodeAll();
function ExplodeSlice($e,$radius)
Explode a single slice a specified radius
Argument | Default | Description |
$e
| | Which slice to explode |
$radius
|
20
| Radius to explode to |
Description
Explode a single slice to a specific radius.
See also
PiePlot::Explode and PiePlot::ExplodeAll
// Explode slice number 2 (the third slice) using the default
// explode radius.
$pieplot->ExplodeSlice(2);
function PiePlot($data)
Constructor for PiePlots
Argument | Default | Description |
$data
| | Data array for Pie |
Description
Construct a new pie plot which later can be added to Piegraph
See also
PieGraph::Add
$pieplot = new PiePlot($slicedata);
$piegraph->Add($pieplot);
function SetCenter($x,$y)
//---------------// PUBLIC METHODS
Argument | Default | Description |
$x
| | X-position as fraction of width |
$y
|
0.5
| Y-position as fraction of height |
Description
Set the center point for the PiePlot
See also
PiePlot::SetSize
$pieplot->SetCenter(0.4,0.5);
function SetColor($aColor)
Specify frame color for pie.
Argument | Default | Description |
$aColor
| | Color. |
Description
Set the color of the border around each slice.
See also
PiePlot::SetSliceColors
$pieplot->SetColor('red');
function SetCSIMTargets($targets,$alts)
Specify URL targets for image maps
Argument | Default | Description |
$targets
| | Array of URL targets |
$alts
|
null
| Alt strings |
Description
Specify list of targets for the image map for each slice. The target should be a fully qualified URL.
Each slice will aslo have it's own 'alt' tag. Depending on the browser this tag is usually showed when the mouse is hold over a poarticular area on the image map. When formatting the alt strings can be specified as a printf() format string. The value supplied to the string will be the value for each slice.
See also
PiePlot::GetCSIMareas
$targets = array('godetail1.html', 'gotodetail2.html' 'gotodetail3.html');
$alts = array('Year %d', 'Year %d', 'Year %d');
$pieplot->SetCSIMTargets($targets,$alts);
function SetFont($family,$style,$size)
Deprecated. Use $pieplot->value->SetFont() instead.
Argument | Default | Description |
$family
| | Font family |
$style
|
FS_NORMAL
| Font style |
$size
|
10
| Font size |
Description
Deprecated. Use $pieplot->value->SetFont() instead.
//Deprecated. Use $pieplot->value->SetFont() instead.
function SetFontColor($aColor)
Deprecated. Use $pieplot->value->SetFontColor() instead.
Argument | Default | Description |
$aColor
| | Color |
Description
Deprecated. Use $pieplot->value->SetFontColor() instead.
//Deprecated. Use $pieplot->value->SetFontColor() instead.
function SetGuideLines($aFlg,$aCurved,$aAlways)
Enable guideline and set drawing policy
Argument | Default | Description |
$aFlg
|
true
| TRUE=Enable guide lines |
$aCurved
|
true
| Curve the labels around the pie |
$aAlways
|
false
| Always use a guide line to the label |
Description
Enable guideline and set drawing policy for guide lines and labels
$pieplot->SetGuideLines();
function SetGuideLinesAdjust($aVFactor,$aRFactor)
Adjuste the distance between labels and labels and pie
Argument | Default | Description |
$aVFactor
| | Vertical fraction |
$aRFactor
|
0.8
| Radius factor |
Description
Adjuste the distance between labels and labels and pie
$graph->xaxis->scale->SetGuideLinesAdjust(1.7);
function SetLabelPos($aLblPosAdj)
Adjust the positoin of slice labels
Argument | Default | Description |
$aLblPosAdj
| | Position as fraction of radius |
Description
Specify the position of the labels for each slice as a fraction of the radius.
Note: The adjustment affect both manually speicfied labels with SetLabels() as well as automtic labels.
See also
PiePlot::SetLabels
$p1 = new PiePlot($data);
$p1->SetLabelPos(0.6);
$graph->Add($p1);
function SetLabels($aLabels,$aLblPosAdj)
Specify individual text labels for all slices
Argument | Default | Description |
$aLabels
| | Arrays of strings |
$aLblPosAdj
|
"auto"
| Position as fraction of the radius |
Description
Normally pie slice gets assigned a label which displays either the percentage or the absolute value of a slice. These automtically asigned labels are positioned in a ring around the pie.
However, you can also manually assign a label to each slice individually with this method.
Each label can contain format specification so for example the label
"May %.1f%%"
would display the in the pie "May 28.3%" assuming you had choosen to use percentage values (SetLabelType())
The second parameter specifies where to position these labels. The position is specified as a fraction of the radius of the pie plot or as the special strine 'auto'. If you specify this string value JpGraph will automtically determine the best position for the labels inside the pie. This is the default if you don't explicitely specify the position.
If you specify a value > 1.0 then the labels will
just be move further out. For example if you specify the position as 1.5 then the labels will move out a further 50% of the current pie radius.
Note: The actual alignment of the labels are dependent on the position. If the labels are just outside the pie they will be individually positioned according to the angle. If the labels are positioned inside the pie then the point of gravity within the text will be aligned with the specified position in the pie.
See also
PiePlot::SetLabelType
$p1->SetLabelType(PIE_VALUE_PER);
$lbl = array("adam\n%.1f%%","bertil\n%.1f%%","kalle\n%.1f%%","peter\n%.1f%%","daniel\n%.1f%%","erik\n%.1f%%");
$p1->SetLabels($lbl);
function SetLabelType($t)
Should we display actual value or percentage?
Argument | Default | Description |
$t
| | Set absolute or percentage value constant |
Description
Specify if the value displayed by each slice (if the $pieplot->value->Show()) have been called shold be absolute or in percent.
The following values are allowed arguments:
- PIE_VALUE_ABS
- PIE_VALUE_PER
- PIE_VALUE_ADJPER. This is a special case of the percentage. Specifying this value will adjust integer percetage values so that the total sum will always be 100%. This is done with the the Hare/Niemeyer method. This makes most sense when used together with a format string for labels of "%d" so it will only display a whole integer value without any deciamals.
-
The defauklt is to show percent.
// Show absolute values
$pieplot->SetLabelType(PIE_VALUE_ABS);
// Display each label with postfix 'kr', e.g. each label will
// look like (for example) 23.5 kr
$pieplot->value->SetFormat('%d kr');
$pieplot->value->Show();
function SetLegends($aLegend)
// Set label arrays
Argument | Default | Description |
$aLegend
| | Array of strings |
Description
Specify an array of text strings that should be used as legends for the slices.
Each text string can be formatted as a printf() format string since when printed they will be passed the value for that slice.
Tip: If you have many evry small slices then the labels close to the pie may be overwriting each other. In this case it is probably better to hide the labels by the slices and instead just show the values ion the legends.
$legends = array('April (%d)','May (%d)','June (%d)');
$pieplot->SetLegends($legends);
function SetShadow($aColor,$aDropWidth)
Add a drop shadow to the pie slices
Argument | Default | Description |
$aColor
|
'darkgray'
| Shadow color |
$aDropWidth
|
4
| Drop distance for shadow |
Description
Add a drop shadow to the pie slices.
This is often more affective if one or more slices are exploded.
// Explode all slices
$p1->ExplodeAll(10);
// Add drop shadow
$p1->SetShadow();
function SetSize($aSize)
// Size in percentage
Argument | Default | Description |
$aSize
| | Size of radius |
Description
If the value specified is between 0 and 1 then it is interpreted as a a fraction of either height or width, whatever is smallest, of the graph.
If the value is >1 then it is interpretated as an absolute size in pixels.
See also
PiePlot::SetCenter
$pieplot->SetSize(0.3);
function SetSliceColors($aColors)
Override theme coplros for slices
Argument | Default | Description |
$aColors
| | Array of colors |
Description
Normally the colors of the slices are set according to what color-theme you are using. You can however, override this by supplying an array of colors to be used for the slices.
If you supply fewer colors than pie-slices than the colors will be re-used from the beginning of the array.
See also
PiePlot::SetTheme
$p1->SetSliceColors(array('red','green','blue'));
function SetStartAngle($aStart)
Speciy start angel for first slice
Argument | Default | Description |
$aStart
| | Start angle in degrees |
Description
Normally the first slice is drawn at 0 degrees, i.e. 3'a clock. With this method you can adjust that to an arbitrary angle. Positive angle will rotate the slice clockwise and a negative angle will move the slice counter-clockwise.
The angle should be specified in degrees.
$pieplot->SetStartAngle(45);
function SetTheme($aTheme)
//Add the last point on the arc
Argument | Default | Description |
$aTheme
| | Theme name |
Description
Specify what color theme should be used for this pie. As of version 1.6.4 the following themes are available:
- "earth"
- "pastel"
- "sand"
- "water"
$pieplot->SetTheme('water');
function SetValueType($aType)
DEPRECATED: See SetLabelType()
Argument | Default | Description |
$aType
| | Value type |
Description
See SetLabelType()
See also
PiePlot::SetLabelType
NA
function ShowBorder($exterior,$interior)
// Should the circle around a pie plot be displayed
Argument | Default | Description |
$exterior
|
true
| Display circle on the outer edge of pieplot |
$interior
|
true
| Display the lines between each slice |
Description
Show the lines between each slice and the border around the pie.
// show both
$pieplot->ShowBorder();