Class PieGraph
- java.lang.Object
-
- org.faceless.graph.Graph
-
- org.faceless.graph.PieGraph
-
public class PieGraph extends Graph
The PieGraph is the only type of Graph that doesn't subclass
AxesGraph, and is ideal for proportional data. As everyone seems to have a different idea as to how a Pie Graph should be laid out, there are a large number of options in this class, some of which are hard to visualize. Check the examples supplied with this package to see what they look like.Pie Graphs always add up to 360 degrees, so you don't need to worry about completing the graph. If the total of the values added to the graph is 100, then a slice with a value of 10 will cover 36 degrees of the pie.
Pie Graph Keys?
As well as the standardGraph.KEY_BOXED_BOTTOMandGraph.KEY_BOXED_RIGHTvalues applicable to all graphs, keys for Pie graphs can be INNER (the value is written on the slice) or OUTER (The value is written next to the graph, with a line to the slice it refers to.)If a slice is too thin to write the label on it, then it is is written next to it and connected with a line. (i.e. the key changes from an INNER to an OUTER for that slice). The
OuterKeyPercentageoption determines whether a slice is considered too thin.To make things more complicated, wherever the text is written you have the option of writing the text ROTATED, on an angle that matches the angle of the slice, or keeping it FLAT. So for example, a slice of pie covering the angles between 12 o'clock and 2 o'clock would have the text written nearly vertically.
To sum up: The different types of key a Pie Graph can have are:
KEY_FLAT_INNER_FLAT_OUTER- Put the label on the slice if it fits, or next to the slice if it doesn't
KEY_FLAT_OUTER- Put the label next to the slice
KEY_ROTATED_OUTER- Put the label next to the slice and rotate it to the same angle as the slice
KEY_ROTATED_INNER_FLAT_OUTER- Put the label on the slice and rotate it to the same angle if it fits: otherwise, put it next to the graph and don't rotate it
KEY_ROTATED_INNER_ROTATED_OUTER- Put the label on the slice if it fits, or next to the slice if it doesn't. Rotate it to the same angle as the slice regardless
KEY_FLAT_INNER_ROTATED_OUTER- Put the label on the slice if it fits, or rotate it and put it next to the slice if it doesn't.
This covers every possible option for laying out keys. Try them all and you'll find one that fits your needs. Most of these are demonstrated in the example PDF document supplied with this package.
Here's an example Pie Graph, showing a few of the options listed above.
import org.faceless.graph.output.ImageOutput; import java.awt.Color; // Create a new Pie Graph, and set some options - give // it a title and set the key type to ROTATED_OUTER. // PieGraph g = new PieGraph(); g.optionTitle("My First Pie Graph"); g.optionDisplayKey(PieGraph.KEY_ROTATED_OUTER); // Add some data to the graph. Use the default // colors for most of them, but make Bananas yellow. // g.set("Apples", 10); g.set("Oranges", 25); g.set("Bananas", 8); g.set("Lemons", 1); g.set("Apricots", 4); g.set("Watermelon", 3); g.setColor("Bananas", Color.yellow); // Highlight the Citrus fruit by extending them away // from the center of the graph (by 20% of it's radius). // g.extendSlice("Oranges", 20); g.extendSlice("Lemons", 20); // Render to an image that's 400x400 // ImageOutput out = new ImageOutput(400,400); out.render(g);
-
-
Field Summary
Fields Modifier and Type Field Description static intKEY_FLAT_INNER_FLAT_OUTERPut the label on the slice if it fits, or next to the slice if itstatic intKEY_FLAT_INNER_ROTATED_OUTERPut the label on the slice if it fits, or rotate it and put it next to the slice if it doesn't.static intKEY_FLAT_OUTERPut the label next to the slicestatic intKEY_ROTATED_INNER_FLAT_OUTERPut the label on the slice and rotate it to the same angle if it fits: otherwise, put it next to the graph and don't rotate it.static intKEY_ROTATED_INNER_ROTATED_OUTERPut the label on the slice if it fits, or next to the slice if it doesn't.static intKEY_ROTATED_OUTERPut the label next to the slice and rotate it to the same angle as the slicestatic intPERCENTAGE_INLINEShow the percentage for each slice directly on the slice, regardless of where the key is shown.static intPERCENTAGE_NONEDo not show the percentage for each slicestatic intPERCENTAGE_WITH_KEYShow the percentage for each slice with the key, wherever it may be.-
Fields inherited from class org.faceless.graph.Graph
canvas, key, KEY_BOXED_BOTTOM, KEY_BOXED_LEFT, KEY_BOXED_RIGHT, KEY_BOXED_TOP, KEY_NONE, keyboxstyle, keypadding, keystyle, keytype, subtitle, subtitlestyle, title, titlepadding, titlestyle, xrotation, yrotation, zrotation
-
-
Constructor Summary
Constructors Constructor Description PieGraph()
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description protected voidcomplete()Complete is the first method that's called by a Graph when it's rendered.voidextendSlice(String name, double radius)Highlight a slice by "extending" it away from the center of the graph.voidoptionDisplayKey(int val)Set the type of key for the Pie Graph.voidoptionDisplayPercentage(int val)Set the type of key for the Pie Graph.voidoptionDisplayZeros(boolean val)Whether to display slices with a value of zero.voidoptionHeight(double val)Set the height of the Pie as a percentage of it's radiusvoidoptionOtherLabel(String val)The name to give to the "Other" slice, if it exists.voidoptionOtherPercentage(double val)The minimum percentage of the pie a slice can be before it's rolled into the "Other" slice.voidoptionOuterKeyLineLength(double val)The length of the line from the edge of the slice to it's label when using anOUTERkey, as a percentage of the radius of the graph.voidoptionOuterKeyPercentage(double val)The minimum percentage of the pie a slice can be before it's key is moved fromINNNERtoOUTER.voidoptionXRotation(double val)How far to rotate the graph around the X-axis (the line running from the left of the graph to the right), in degrees.voidoptionYRotation(double val)How far to rotate the graph around the Y-axis (the line running from the top of the graph to the bottom), in degrees.protected voidpostpostcomplete()The unfortunately named PostPostComplete is called last of all by a Graph when it's rendered, to add anything that couldn't quite be laid out correctly on the last pass - usually Text dependant on the position of other text.voidset(String name, double val)Set a data value.voidsetColor(String name, Paint color)Change the color of a slice.-
Methods inherited from class org.faceless.graph.Graph
addElement, getDefaultBorderColor, getFontScale, optionFixedAspectRatio, optionKeyBoxStyle, optionKeyStyle, optionRemoveBackFace, optionSubTitle, optionSubTitleStyle, optionTitle, optionTitleStyle, optionZRotation, postcomplete, setDefaultBorderColor, setDefaultColors, setDefaultLineThickness, setFontScale, setLicenseKey, setLightLevel, setLightVector, setPieEdgeDegrees, toCanvas
-
-
-
-
Field Detail
-
KEY_FLAT_INNER_FLAT_OUTER
public static final int KEY_FLAT_INNER_FLAT_OUTER
Put the label on the slice if it fits, or next to the slice if it- See Also:
- Constant Field Values
-
KEY_ROTATED_INNER_FLAT_OUTER
public static final int KEY_ROTATED_INNER_FLAT_OUTER
Put the label on the slice and rotate it to the same angle if it fits: otherwise, put it next to the graph and don't rotate it.- See Also:
- Constant Field Values
-
KEY_FLAT_INNER_ROTATED_OUTER
public static final int KEY_FLAT_INNER_ROTATED_OUTER
Put the label on the slice if it fits, or rotate it and put it next to the slice if it doesn't.- See Also:
- Constant Field Values
-
KEY_ROTATED_INNER_ROTATED_OUTER
public static final int KEY_ROTATED_INNER_ROTATED_OUTER
Put the label on the slice if it fits, or next to the slice if it doesn't. Rotate it to the same angle as the slice regardless.- See Also:
- Constant Field Values
-
KEY_FLAT_OUTER
public static final int KEY_FLAT_OUTER
Put the label next to the slice- See Also:
- Constant Field Values
-
KEY_ROTATED_OUTER
public static final int KEY_ROTATED_OUTER
Put the label next to the slice and rotate it to the same angle as the slice- See Also:
- Constant Field Values
-
PERCENTAGE_NONE
public static final int PERCENTAGE_NONE
Do not show the percentage for each slice- See Also:
- Constant Field Values
-
PERCENTAGE_WITH_KEY
public static final int PERCENTAGE_WITH_KEY
Show the percentage for each slice with the key, wherever it may be.- See Also:
- Constant Field Values
-
PERCENTAGE_INLINE
public static final int PERCENTAGE_INLINE
Show the percentage for each slice directly on the slice, regardless of where the key is shown.- See Also:
- Constant Field Values
-
-
Method Detail
-
setColor
public void setColor(String name, Paint color)
Change the color of a slice.- Parameters:
name- The name of the slice. If it doesn't exist, it's created.color- The color of the slice.
-
extendSlice
public void extendSlice(String name, double radius)
Highlight a slice by "extending" it away from the center of the graph.- Parameters:
name- The name of the slice. If it doesn't exist, it's created in the next default color.radius- the distance to extend the slice, as a percentage of the radius of the graph
-
set
public void set(String name, double val)
Set a data value.- Parameters:
name- The name of the slice. If it doesn't exist, it's created in the next default color.val- the value to set this slice to
-
optionDisplayKey
public void optionDisplayKey(int val)
Set the type of key for the Pie Graph. As well as theGraph.KEY_NONE,Graph.KEY_BOXED_BOTTOM,Graph.KEY_BOXED_TOP,Graph.KEY_BOXED_LEFTandGraph.KEY_BOXED_RIGHToptions, Pie-Graphs can also haveKEY_ROTATED_INNER_FLAT_OUTER,KEY_ROTATED_INNER_ROTATED_OUTER,KEY_FLAT_INNER_FLAT_OUTER,KEY_FLAT_INNER_ROTATED_OUTER,KEY_ROTATED_OUTERandKEY_FLAT_OUTER.Default: KEY_BOXED_BOTTOM
- Overrides:
optionDisplayKeyin classGraph
-
optionHeight
public void optionHeight(double val)
Set the height of the Pie as a percentage of it's radiusDefault: 15
-
optionDisplayZeros
public void optionDisplayZeros(boolean val)
Whether to display slices with a value of zero. A zero-width slice appears on the graph as a line.Default: false
- Since:
- 1.0.7
-
optionDisplayPercentage
public void optionDisplayPercentage(int val)
Set the type of key for the Pie Graph. Where, if anywhere, to show the percentage of each slice. Valid values arePERCENTAGE_NONE,PERCENTAGE_WITH_KEY(to show the percentage as part of the key), orPERCENTAGE_INLINE(to show the percentage figures on the pie itself, even if the key is boxed).Default:
PERCENTAGE_NONE
-
optionOtherPercentage
public void optionOtherPercentage(double val)
The minimum percentage of the pie a slice can be before it's rolled into the "Other" slice. If you don't want an "Other" slice, leave it set to zeroDefault: 0
-
optionOtherLabel
public void optionOtherLabel(String val)
The name to give to the "Other" slice, if it exists.Default: "Other"
-
optionOuterKeyPercentage
public void optionOuterKeyPercentage(double val)
The minimum percentage of the pie a slice can be before it's key is moved fromINNNERtoOUTER. Has no effect if a key isBOXEDor alreadyOUTER. See the class preamble for a description of the various key types.Default: 3.0
-
optionOuterKeyLineLength
public void optionOuterKeyLineLength(double val)
The length of the line from the edge of the slice to it's label when using anOUTERkey, as a percentage of the radius of the graph.Default: 20
-
optionYRotation
public void optionYRotation(double val)
Description copied from class:GraphHow far to rotate the graph around the Y-axis (the line running from the top of the graph to the bottom), in degrees.Default: 0
- Overrides:
optionYRotationin classGraph
-
optionXRotation
public void optionXRotation(double val)
Description copied from class:GraphHow far to rotate the graph around the X-axis (the line running from the left of the graph to the right), in degrees.Default: 0
- Overrides:
optionXRotationin classGraph
-
complete
protected void complete()
Description copied from class:GraphComplete is the first method that's called by a Graph when it's rendered. It should take the data from the dataset and add the various elements that it needs to the Graph. The first thing it should do, however, is callsuper.complete().
-
postpostcomplete
protected void postpostcomplete()
Description copied from class:GraphThe unfortunately named PostPostComplete is called last of all by a Graph when it's rendered, to add anything that couldn't quite be laid out correctly on the last pass - usually Text dependant on the position of other text. The last thing it should do before returning is callsuper.postpostcomplete()- Overrides:
postpostcompletein classGraph
-
-