org.faceless.graph2
Class PieGraph

java.lang.Object
  extended by org.faceless.graph2.Graph
      extended by org.faceless.graph2.PieGraph

public class PieGraph
extends Graph

A subclass of graph for displaying data in a circular Pie graph. This is the only type of graph that isn't plotted against an Axis. Plotting a PieGraph is much simpler than plotting an 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.


Field Summary
 
Fields inherited from class org.faceless.graph2.Graph
VERSION
 
Constructor Summary
PieGraph()
          Create a new PieGraph
 
Method Summary
 void addLabel(String key, AbstractMarker marker, double distance, Style callout)
          Add a label to one of the slices in the pie.
 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 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.
 
Methods inherited from class org.faceless.graph2.Graph
addKey, addKey, addText, draw, interrupt, isInterrupted, setAutoColors, setColorOrdering, setDefaultColors, setFixedAspectRatio, setFixedSize, setLicenseKey, setLightLevel, setLightVector, setMetaData, setXRotation, setYRotation, setZRotation
 
Methods inherited from class java.lang.Object
equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

PieGraph

public PieGraph()
Create a new PieGraph

Method Detail

setDoughnut

public void setDoughnut(double size)
Set the size of the "hole in the doughnut". By default this value is set to 0, which means there is no hole (the graph is a regular Pie graph). Values between 0 and 99 may be specified - 99 would result in a very thin ring graph.

Parameters:
size - the size of the doughnut hole - from 0 to 99
Since:
2.1

setSliceSize

public void setSliceSize(double size)
Set the number of degrees each straight line makes up in a PieGraph. Smaller values give rounder pies and smoother shading, but will a) take longer to render and b) for vector files like PDF or SVG, result in larger files (although this may be minimized by compression in PDF). The default value in versions prior to 2.1 was 5, and since then is 2 (giving 2° steps). This value gives high quality results, but when painting with createPattern() will result in much slower rendering. The minimal value is 0.5 and the maximum is 5.

Since:
2.1.1

set

public void set(String name,
                double value)
Add a slice to the Pie. If a slice with this name already exists, it's value is replaced. To remove a slice completely, set the value to NaN. Note that since 2.3, 0 value slices are allowed.

Parameters:
name - the name of the slice
value - the size of the slice

getProportion

public double getProportion(String name)
Return the proportion of the pie that the named slice occupies. If the specified name is not in the pie this method returns 0. If you're using an "other" slice (by calling setOtherSlice(java.lang.String, double)), then passing in the name of that slice will give you the proportion it occupies.

Parameters:
name - the name of the slice to get the proportion of
Returns:
the proportion of the pie occupied by this slice, between 0 and 1
Since:
2.0.2

setColor

public void setColor(String name,
                     Paint color)
Set the color for the specified slice

Parameters:
name - the name of the slice
color - the color to paint the slice in

setStyle

public void setStyle(Style style)
Set the overall style for the graph. This allows control over non-color features of the graph, such as border-color, thickness and so on.

Since:
2.0.4

setExtend

public void setExtend(String name,
                      double radius)
Extend the specified slice away from the center of the pie

Parameters:
name - the name of the slice
radius - 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.2

setLabel

public void setLabel(String key,
                     AbstractMarker marker,
                     double distance)
Set the label of one of the slices in the pie. This method replaces any existing labels on this slice and then calls addLabel() with null for the value of callout.

Parameters:
key - the slice to add the label to
marker - 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.
See Also:
addLabel(java.lang.String, org.faceless.graph2.AbstractMarker, double, org.faceless.graph2.Style)

addLabel

public void addLabel(String key,
                     AbstractMarker marker,
                     double distance,
                     Style callout)
Add a label to one of the slices in the pie. Whether the label is displayed on or off the Pie depends on whether 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.

Parameters:
key - the slice to add the label to
marker - 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.
Since:
2.1

setDepth

public void setDepth(double depth)
Set the depth of the Pie when it's displayed in 3-D. The default is 15, for 15%

Parameters:
depth - the depth of the Pie, as a percentage of the radius of the pie

setOtherSlice

public 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. By default, no "Other" slice is used.

Parameters:
name - the name to use for the slice
percentage - 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-2011 Big Faceless Organization