|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Objectorg.faceless.graph.Graph
org.faceless.graph.PieGraph
public class PieGraph
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 standard
Graph.KEY_BOXED_BOTTOM
and Graph.KEY_BOXED_RIGHT
values
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 OuterKeyPercentage
option
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
KEY_FLAT_OUTER
KEY_ROTATED_OUTER
KEY_ROTATED_INNER_FLAT_OUTER
KEY_ROTATED_INNER_ROTATED_OUTER
KEY_FLAT_INNER_ROTATED_OUTER
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 | |
---|---|
static int |
KEY_FLAT_INNER_FLAT_OUTER
Put the label on the slice if it fits, or next to the slice if it |
static 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. |
static int |
KEY_FLAT_OUTER
Put the label next to the slice |
static 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. |
static int |
KEY_ROTATED_INNER_ROTATED_OUTER
Put the label on the slice if it fits, or next to the slice if it doesn't. |
static int |
KEY_ROTATED_OUTER
Put the label next to the slice and rotate it to the same angle as the slice |
static int |
PERCENTAGE_INLINE
Show the percentage for each slice directly on the slice, regardless of where the key is shown. |
static int |
PERCENTAGE_NONE
Do not show the percentage for each slice |
static int |
PERCENTAGE_WITH_KEY
Show the percentage for each slice with the key, wherever it may be. |
Fields inherited from class org.faceless.graph.Graph |
---|
KEY_BOXED_BOTTOM, KEY_BOXED_LEFT, KEY_BOXED_RIGHT, KEY_BOXED_TOP, KEY_NONE |
Constructor Summary | |
---|---|
PieGraph()
|
Method Summary | |
---|---|
void |
extendSlice(String name,
double radius)
Highlight a slice by "extending" it away from the center of the graph. |
void |
optionDisplayKey(int val)
Set the type of key for the Pie Graph. |
void |
optionDisplayPercentage(int val)
Set the type of key for the Pie Graph. |
void |
optionDisplayZeros(boolean val)
Whether to display slices with a value of zero. |
void |
optionHeight(double val)
Set the height of the Pie as a percentage of it's radius Default: 15 |
void |
optionOtherLabel(String val)
The name to give to the "Other" slice, if it exists. |
void |
optionOtherPercentage(double val)
The minimum percentage of the pie a slice can be before it's rolled into the "Other" slice. |
void |
optionOuterKeyLineLength(double val)
The length of the line from the edge of the slice to it's label when using an OUTER key, as a percentage of the radius of
the graph. |
void |
optionOuterKeyPercentage(double val)
The minimum percentage of the pie a slice can be before it's key is moved from INNNER to OUTER . |
void |
optionXRotation(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. |
void |
optionYRotation(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. |
void |
set(String name,
double val)
Set a data value. |
void |
setColor(String name,
Paint color)
Change the color of a slice. |
Methods inherited from class org.faceless.graph.Graph |
---|
getDefaultBorderColor, getFontScale, optionFixedAspectRatio, optionKeyBoxStyle, optionKeyStyle, optionSubTitle, optionSubTitleStyle, optionTitle, optionTitleStyle, optionZRotation, setDefaultBorderColor, setDefaultColors, setDefaultLineThickness, setFontScale, setLicenseKey, setLightLevel, setLightVector, setPieEdgeDegrees, toCanvas |
Methods inherited from class java.lang.Object |
---|
equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
Field Detail |
---|
public static final int KEY_FLAT_INNER_FLAT_OUTER
public static final int KEY_ROTATED_INNER_FLAT_OUTER
public static final int KEY_FLAT_INNER_ROTATED_OUTER
public static final int KEY_ROTATED_INNER_ROTATED_OUTER
public static final int KEY_FLAT_OUTER
public static final int KEY_ROTATED_OUTER
public static final int PERCENTAGE_NONE
public static final int PERCENTAGE_WITH_KEY
public static final int PERCENTAGE_INLINE
Constructor Detail |
---|
public PieGraph()
Method Detail |
---|
public void setColor(String name, Paint color)
name
- The name of the slice. If it doesn't exist, it's created.color
- The color of the slice.public void extendSlice(String name, double radius)
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 graphpublic void set(String name, double val)
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 topublic void optionDisplayKey(int val)
Graph.KEY_NONE
, Graph.KEY_BOXED_BOTTOM
, Graph.KEY_BOXED_TOP
,
Graph.KEY_BOXED_LEFT
and Graph.KEY_BOXED_RIGHT
options, Pie-Graphs
can also have
KEY_ROTATED_INNER_FLAT_OUTER
,
KEY_ROTATED_INNER_ROTATED_OUTER
,
KEY_FLAT_INNER_FLAT_OUTER
,
KEY_FLAT_INNER_ROTATED_OUTER
,
KEY_ROTATED_OUTER
and
KEY_FLAT_OUTER
.
Default: KEY_BOXED_BOTTOM
optionDisplayKey
in class Graph
public void optionHeight(double val)
Default: 15
public void optionDisplayZeros(boolean val)
Default: false
public void optionDisplayPercentage(int val)
PERCENTAGE_NONE
, PERCENTAGE_WITH_KEY
(to show the
percentage as part of the key), or PERCENTAGE_INLINE
(to show
the percentage figures on the pie itself, even if the key is boxed).
Default: PERCENTAGE_NONE
public void optionOtherPercentage(double val)
Default: 0
public void optionOtherLabel(String val)
Default: "Other"
public void optionOuterKeyPercentage(double val)
INNNER
to OUTER
. Has no effect
if a key is BOXED
or already OUTER
. See
the class preamble for a description of the various key types.
Default: 3.0
public void optionOuterKeyLineLength(double val)
OUTER
key, as a percentage of the radius of
the graph.
Default: 20
public void optionYRotation(double val)
Graph
Default: 0
optionYRotation
in class Graph
public void optionXRotation(double val)
Graph
Default: 0
optionXRotation
in class Graph
|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |