public class PieGraph extends Graph
AxesGraph
.
Here's a simple example:
PieGraph graph = new PieGraph(); graph.set("Apples", 200); graph.set("Oranges", 100);Labels can be added to each slice by calling the
setLabel
method.Constructor and Description |
---|
PieGraph()
Create a new PieGraph
|
Modifier and Type | Method and Description |
---|---|
void |
addLabel(String key,
AbstractMarker marker,
double distance,
Style callout)
Add a label to one of the slices in the pie.
|
void |
addLabel(String key,
AbstractMarker marker,
double distance,
Style callout,
int align)
Add a label to one of the slices in the pie.
|
void |
addLine(String name,
double x1,
double y1,
double x2,
double y2,
Style style)
Add a line to the graph.
|
void |
addMarker(AbstractMarker marker,
double x,
double y)
Add an AbstractMarker at an arbitrary cartesion point on the graph.
|
void |
addPolarMarker(AbstractMarker marker,
double angle,
double distance)
Add an AbstractMarker at an arbitrary polar coordinate on the graph.
|
double |
getProportion(String name)
Return the proportion of the pie that the named slice occupies.
|
void |
set(String name,
double value)
Add a slice to the Pie.
|
void |
setColor(String name,
Paint color)
Set the color for the specified slice
|
void |
setDepth(double depth)
Set the depth of the Pie when it's displayed in 3-D.
|
void |
setDoughnut(double size)
Set the size of the "hole in the doughnut".
|
void |
setExtend(String name,
double radius)
Extend the specified slice away from the center of the pie.
|
void |
setExtend(String name,
double centerradius,
double innerradius,
double outerradius)
Extend the specified slice away from the center of the pie, and set the
inner and outer radius of the slice.
|
void |
setLabel(String key,
AbstractMarker marker,
double distance)
Set the label of one of the slices in the pie.
|
void |
setOtherSlice(String name,
double percentage)
Create an "Other" slice, which can be used to group slices that
are too small to show useful information.
|
void |
setSliceSize(double size)
Set the number of degrees each straight line makes up in a PieGraph.
|
void |
setStyle(Style style)
Set the overall style for the graph.
|
addKey, addKey, addText, draw, getActualOffset, getActualZoom, interrupt, isInterrupted, isOverlapping, setAutoColors, setColorOrdering, setDefaultColors, setFixedAspectRatio, setFixedSize, setLicenseKey, setLightLevel, setLightVector, setMetaData, setOption, setXRotation, setYRotation, setZRotation
public void addPolarMarker(AbstractMarker marker, double angle, double distance)
marker
- the markerangle
- the angle of the graph, in degrees clockwise from 12 o'clockdistance
- the distance from the center of the graph as a proportion of the radius;
1 is the radius of the graph.public void addMarker(AbstractMarker marker, double x, double y)
marker
- the markerx
- the X position of the marker, where -100 is the left side, 0 is the center and 100 the right-side of the graph.y
- the Y position of the marker, where 100 is the top side, 0 is the center and -100 the bottom-side of the graph.public void addLine(String name, double x1, double y1, double x2, double y2, Style style)
x1
- the first X position of the line, where -100 is the left side, 0 is the center and 100 the right-side of the graph.y1
- the first Y position of the line, where 100 is the top side, 0 is the center and -100 the bottom-side of the graph.x2
- the second X position of the liney2
- the second Y position of the linestyle
- the Style to draw the line inpublic void setDoughnut(double size)
size
- the size of the doughnut hole - from 0 to 99public void setSliceSize(double size)
createPattern()
will result in much slower rendering. The minimal value is 0.5 and the maximum is 5.public void set(String name, double value)
name
- the name of the slicevalue
- the size of the slicepublic double getProportion(String name)
setOtherSlice(java.lang.String, double)
),
then passing in the name of that slice will give you the proportion
it occupies.name
- the name of the slice to get the proportion ofpublic void setColor(String name, Paint color)
name
- the name of the slicecolor
- the color to paint the slice inpublic void setStyle(Style style)
public void setExtend(String name, double radius)
setExtend
(name, radius, 0, 1)name
- the name of the sliceradius
- the distance from the center of the pie to move the slice,
as a percentage of the radius of the pie. Typical values would be about 0.2public void setExtend(String name, double centerradius, double innerradius, double outerradius)
name
- the name of the slicecenterradius
- the distance from the center of the pie to move the slice,
as a percentage of the radius of the pie. Typical values would be about 0.2innerradius
- the distance from the center of the slice to the inner
edge - a value of 0 draws a complete slice, a value of 0.5 will result in the
inner 50% of the slice not being drawn - the slice is part of a "doughnut"
rather than a pie.outerradius
- the distance from the center of the slice to the outer
edge - a value of 1 draws the slice the same size as the rest of the pie,
a value of 1.2 will extend the slice 20% beyond the edge.setDoughnut(double)
public void setLabel(String key, AbstractMarker marker, double distance)
addLabel()
with null
for the value of callout
.key
- the slice to add the label tomarker
- the marker to display. May be a Text
, Marker
or Image
distance
- How far from the center of the pie to put the slice, as a ratio of the radius.For example, a value of 1.2 puts the marker just outside the edge of the pie and a value of 0.7 puts it inside the pie. A value of 0 or NaN will auto-position the labeladdLabel(java.lang.String, org.faceless.graph2.AbstractMarker, double, org.faceless.graph2.Style)
public void addLabel(String key, AbstractMarker marker, double distance, Style callout)
addLabel(key, marker, distance, callout, 0)
addLabel(String,AbstractMarker,double,Style,int)
public void addLabel(String key, AbstractMarker marker, double distance, Style callout, int align)
distance
is less than or
greater than 0. Labels may be rotated by specifying a value to TextStyle.setRotate(double)
when creating the label, and the special value TextStyle.ROTATE_AUTO
may be used to cause labels to rotate to match the slice. Slices may have multiple
labels.
The optional callout
parameter is the style to draw the line to that
label in when distance
is greater than 1. It may be null
,
in which case no line will be drawn.
As a special case for Pie Graphs, if the marker is a Text
object
containing the text "0%%", "0.0%%" or "0.00%%", that text will be replaced
by the the size of the slice as a percentage. If this isn't flexible enough
the value from getProportion(java.lang.String)
can be formatted as required.
key
- the slice to add the label tomarker
- the marker to display. May be a Text
, Marker
or Image
distance
- How far from the center of the pie to put the slice, as a ratio of the radius.For example, a value of 1.2 puts the marker just outside the edge of the pie and a value of 0.7 puts it inside the pie.callout
- The style to draw the line to the marker from the edge of the pie. For
labels with a distance
of < 0, this value is ignored.align
- if non-zero, this alignment is set on the label instead of being automatically selected.public void setDepth(double depth)
depth
- the depth of the Pie, as a percentage of the radius of the piepublic void setOtherSlice(String name, double percentage)
name
- the name to use for the slicepercentage
- the threshold to determine which slices to add. Any slices
that would be smaller than this percentage are added to the other slice
instead of being displayed directly. Zero means no other slice is used.Copyright © 2001-2016 Big Faceless Organization