com.jrefinery.chart
Class PiePlot

java.lang.Object
  extended by com.jrefinery.chart.Plot
      extended by com.jrefinery.chart.PiePlot
All Implemented Interfaces:
AxisConstants, com.jrefinery.chart.event.AxisChangeListener, DatasetChangeListener

public class PiePlot
extends Plot

A plot that displays data in the form of a pie chart, using data from any class that implements the PieDataset interface.

Notes: (1) negative values in the dataset are ignored; (2) vertical axis and horizontal axis are set to null; (3) there are utility methods for creating a PieDataset from a CategoryDataset;

See Also:
Plot, PieDataset

Field Summary
protected  boolean circular
          Flag determining whether to draw an ellipse or a perfect circle.
static double DEFAULT_INTERIOR_GAP
          The default interior gap percent (currently 20%).
static double DEFAULT_RADIUS
          The default radius percent (currently 100%).
static java.awt.Font DEFAULT_SECTION_LABEL_FONT
          The default section label font.
static double DEFAULT_SECTION_LABEL_GAP
          The default section label gap (currently 10%).
static java.awt.Paint DEFAULT_SECTION_LABEL_PAINT
          The default section label paint.
protected  double[] explodePercentages
          The percentage amount to explode each pie section.
protected  double interiorGapPercent
          The amount of space left around the outside of the pie plot, expressed as a percentage.
static double MAX_INTERIOR_GAP
          The maximum interior gap (currently 40%).
static double MAX_RADIUS
          The maximum radius (currently 100%).
static double MAX_SECTION_LABEL_GAP
          The maximum interior gap (currently 30%).
static int NAME_AND_PERCENT_LABELS
          Constant indicating percent labels on the pie sections.
static int NAME_AND_VALUE_LABELS
          Constant indicating percent labels on the pie sections.
static int NAME_LABELS
          Constant indicating name labels on the pie sections.
static int NO_LABELS
          Constant indicating no labels on the pie sections.
static int PERCENT_LABELS
          Constant indicating percent labels on the pie sections.
protected  java.text.DecimalFormat percentFormatter
           
protected  double radiusPercent
          The radius as a percentage of the available drawing area.
protected  java.awt.Font sectionLabelFont
          The font used to display the section labels.
protected  double sectionLabelGapPercent
          The gap between the labels and the pie sections, as a percentage of the radius.
protected  java.awt.Paint sectionLabelPaint
          The color used to draw the section labels.
protected  int sectionLabelType
          Label type (NO_LABELS, NAME_LABELS, PERCENT_LABELS, NAME_AND_PERCENT_LABELS).
protected  com.jrefinery.chart.tooltips.PieToolTipGenerator toolTipGenerator
          The tool tip generator.
static int VALUE_AND_PERCENT_LABELS
          Constant indicating percent labels on the pie sections.
static int VALUE_LABELS
          Constant indicating value labels on the pie sections.
protected  java.text.DecimalFormat valueFormatter
           
 
Fields inherited from class com.jrefinery.chart.Plot
backgroundAlpha, backgroundImage, backgroundPaint, dataset, DEFAULT_BACKGROUND_ALPHA, DEFAULT_BACKGROUND_PAINT, DEFAULT_FOREGROUND_ALPHA, DEFAULT_INSETS, DEFAULT_OUTLINE_PAINT, DEFAULT_OUTLINE_STROKE, firstSeriesIndex, foregroundAlpha, insets, listeners, MINIMUM_HEIGHT_TO_DRAW, MINIMUM_WIDTH_TO_DRAW, outlinePaint, outlineStroke, seriesOutlinePaint, seriesOutlineStroke, seriesPaint, seriesStroke, shapeFactory, ZERO
 
Fields inherited from interface com.jrefinery.chart.AxisConstants
DEFAULT_AXIS_LABEL_FONT, DEFAULT_AXIS_LABEL_INSETS, DEFAULT_AXIS_LABEL_PAINT, DEFAULT_TICK_LABEL_FONT, DEFAULT_TICK_LABEL_INSETS, DEFAULT_TICK_LABEL_PAINT, DEFAULT_TICK_STROKE
 
Constructor Summary
PiePlot(PieDataset data)
          Constructs a new pie plot, using default attributes as required.
PiePlot(PieDataset data, java.awt.Insets insets, java.awt.Paint backgroundPaint, java.awt.Image backgroundImage, float backgroundAlpha, java.awt.Stroke outlineStroke, java.awt.Paint outlinePaint, float foregroundAlpha, double interiorGapPercent, boolean circular, double radiusPercent, int sectionLabelType, java.awt.Font sectionLabelFont, java.awt.Paint sectionLabelPaint, double sectionLabelGapPercent, java.lang.String valueFormatString, java.lang.String percentFormatString, com.jrefinery.chart.tooltips.PieToolTipGenerator tooltipGenerator)
          Constructs a pie plot.
 
Method Summary
protected  java.awt.geom.Point2D calculateLabelLocation(java.awt.geom.Rectangle2D labelBounds, double ascent, java.awt.geom.Rectangle2D unexploded, java.awt.geom.Rectangle2D exploded, double startAngle, double extent, double explodePercent)
          Returns the location for a label, taking into account whether or not the pie section is exploded.
 void draw(java.awt.Graphics2D g2, java.awt.geom.Rectangle2D plotArea, ChartRenderingInfo info)
          Draws the plot on a Java 2D graphics device (such as the screen or a printer).
protected  void drawLabel(java.awt.Graphics2D g2, java.awt.geom.Rectangle2D pieArea, java.awt.geom.Rectangle2D explodedPieArea, PieDataset data, double value, int section, double startAngle, double extent)
          Draws the label for one pie section.
protected  java.awt.geom.Rectangle2D getArcBounds(java.awt.geom.Rectangle2D unexploded, java.awt.geom.Rectangle2D exploded, double startAngle, double extent, double explodePercent)
          Returns a rectangle that can be used to create a pie section (taking into account the amount by which the pie section is 'exploded').
 java.util.Collection getCategories()
          Returns a collection of the categories in the dataset.
 double getExplodePercent(int section)
          Returns the amount that a section should be 'exploded'.
 double getInteriorGapPercent()
          Returns the interior gap, measures as a percentage of the available drawing space.
 java.util.List getLegendItemLabels()
          Returns a list of labels for the legend.
 PieDataset getPieDataset()
          Returns the dataset for the plot, cast as a PieDataset.
 java.lang.String getPlotType()
          Returns a short string describing the type of plot.
 double getRadiusPercent()
          Returns the radius percentage.
 java.awt.Font getSectionLabelFont()
          Returns the section label font.
 double getSectionLabelGapPercent()
          Returns the section label gap, measures as a percentage of the radius.
 java.awt.Paint getSectionLabelPaint()
          Returns the section label paint.
 int getSectionLabelType()
          Returns the section label type.
 com.jrefinery.chart.tooltips.PieToolTipGenerator getToolTipGenerator()
          Returns the tooltip generator (possibly null).
 boolean isCircular()
          Returns a flag indicating whether the pie chart is circular, or stretched into an elliptical shape.
 boolean isCompatibleHorizontalAxis(Axis axis)
          Returns true if the axis is compatible with the pie plot, and false otherwise.
 boolean isCompatibleVerticalAxis(Axis axis)
          Returns true if the axis is compatible with the pie plot, and false otherwise.
 void setCircular(boolean flag)
          A flag indicating whether the pie chart is circular, or stretched into an elliptical shape.
 void setExplodePercent(int section, double percent)
          Sets the amount that a pie section should be exploded.
 void setInteriorGapPercent(double percent)
          Sets the interior gap percent.
 void setPercentFormatString(java.lang.String format)
          Sets the format string for the percent labels.
 void setRadiusPercent(double percent)
          Sets the radius percentage.
 void setSectionLabelFont(java.awt.Font font)
          Sets the section label font.
 void setSectionLabelGapPercent(double percent)
          Sets the section label gap percent.
 void setSectionLabelPaint(java.awt.Paint paint)
          Sets the section label paint.
 void setSectionLabelType(int type)
          Sets the section label type.
 void setToolTipGenerator(com.jrefinery.chart.tooltips.PieToolTipGenerator generator)
          Sets the tooltip generator.
 void setValueFormatString(java.lang.String format)
          Sets the format string for the value labels.
 void zoom(double percent)
          A zoom method that does nothing.
 
Methods inherited from class com.jrefinery.chart.Plot
addChangeListener, axisChanged, datasetChanged, drawOutlineAndBackground, getBackgroundAlpha, getBackgroundPaint, getDataset, getFirstSeriesIndex, getForegroundAlpha, getInsets, getOutlinePaint, getOutlineStroke, getSeriesOutlinePaint, getSeriesOutlineStroke, getSeriesPaint, getSeriesStroke, getShape, getShape, getShapeFactory, handleClick, isSubplot, notifyListeners, removeChangeListener, setBackgroundAlpha, setBackgroundImage, setBackgroundPaint, setDataset, setFirstSeriesIndex, setForegroundAlpha, setInsets, setOutlinePaint, setOutlineStroke, setSeriesOutlinePaint, setSeriesOutlineStroke, setSeriesOutlineStroke, setSeriesPaint, setSeriesPaint, setSeriesStroke, setSeriesStroke, setShapeFactory
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

DEFAULT_INTERIOR_GAP

public static final double DEFAULT_INTERIOR_GAP
The default interior gap percent (currently 20%).

See Also:
Constant Field Values

MAX_INTERIOR_GAP

public static final double MAX_INTERIOR_GAP
The maximum interior gap (currently 40%).

See Also:
Constant Field Values

DEFAULT_RADIUS

public static final double DEFAULT_RADIUS
The default radius percent (currently 100%).

See Also:
Constant Field Values

MAX_RADIUS

public static final double MAX_RADIUS
The maximum radius (currently 100%).

See Also:
Constant Field Values

DEFAULT_SECTION_LABEL_FONT

public static final java.awt.Font DEFAULT_SECTION_LABEL_FONT
The default section label font.


DEFAULT_SECTION_LABEL_PAINT

public static final java.awt.Paint DEFAULT_SECTION_LABEL_PAINT
The default section label paint.


DEFAULT_SECTION_LABEL_GAP

public static final double DEFAULT_SECTION_LABEL_GAP
The default section label gap (currently 10%).

See Also:
Constant Field Values

MAX_SECTION_LABEL_GAP

public static final double MAX_SECTION_LABEL_GAP
The maximum interior gap (currently 30%).

See Also:
Constant Field Values

NO_LABELS

public static final int NO_LABELS
Constant indicating no labels on the pie sections.

See Also:
Constant Field Values

NAME_LABELS

public static final int NAME_LABELS
Constant indicating name labels on the pie sections.

See Also:
Constant Field Values

VALUE_LABELS

public static final int VALUE_LABELS
Constant indicating value labels on the pie sections.

See Also:
Constant Field Values

PERCENT_LABELS

public static final int PERCENT_LABELS
Constant indicating percent labels on the pie sections.

See Also:
Constant Field Values

NAME_AND_VALUE_LABELS

public static final int NAME_AND_VALUE_LABELS
Constant indicating percent labels on the pie sections.

See Also:
Constant Field Values

NAME_AND_PERCENT_LABELS

public static final int NAME_AND_PERCENT_LABELS
Constant indicating percent labels on the pie sections.

See Also:
Constant Field Values

VALUE_AND_PERCENT_LABELS

public static final int VALUE_AND_PERCENT_LABELS
Constant indicating percent labels on the pie sections.

See Also:
Constant Field Values

interiorGapPercent

protected double interiorGapPercent
The amount of space left around the outside of the pie plot, expressed as a percentage.


circular

protected boolean circular
Flag determining whether to draw an ellipse or a perfect circle.


radiusPercent

protected double radiusPercent
The radius as a percentage of the available drawing area.


sectionLabelType

protected int sectionLabelType
Label type (NO_LABELS, NAME_LABELS, PERCENT_LABELS, NAME_AND_PERCENT_LABELS).


sectionLabelFont

protected java.awt.Font sectionLabelFont
The font used to display the section labels.


sectionLabelPaint

protected java.awt.Paint sectionLabelPaint
The color used to draw the section labels.


sectionLabelGapPercent

protected double sectionLabelGapPercent
The gap between the labels and the pie sections, as a percentage of the radius.


explodePercentages

protected double[] explodePercentages
The percentage amount to explode each pie section.


valueFormatter

protected java.text.DecimalFormat valueFormatter

percentFormatter

protected java.text.DecimalFormat percentFormatter

toolTipGenerator

protected com.jrefinery.chart.tooltips.PieToolTipGenerator toolTipGenerator
The tool tip generator.

Constructor Detail

PiePlot

public PiePlot(PieDataset data)
Constructs a new pie plot, using default attributes as required.

Parameters:
data - The data.

PiePlot

public PiePlot(PieDataset data,
               java.awt.Insets insets,
               java.awt.Paint backgroundPaint,
               java.awt.Image backgroundImage,
               float backgroundAlpha,
               java.awt.Stroke outlineStroke,
               java.awt.Paint outlinePaint,
               float foregroundAlpha,
               double interiorGapPercent,
               boolean circular,
               double radiusPercent,
               int sectionLabelType,
               java.awt.Font sectionLabelFont,
               java.awt.Paint sectionLabelPaint,
               double sectionLabelGapPercent,
               java.lang.String valueFormatString,
               java.lang.String percentFormatString,
               com.jrefinery.chart.tooltips.PieToolTipGenerator tooltipGenerator)
Constructs a pie plot.

Parameters:
data - The data.
insets - Amount of blank space around the plot area.
backgroundPaint - An optional color for the plot's background.
backgroundImage - An optional image for the plot's background.
backgroundAlpha - Alpha-transparency for the plot's background.
outlineStroke - The Stroke used to draw an outline around the plot.
outlinePaint - The color used to draw an outline around the plot.
foregroundAlpha - The alpha-transparency for the plot.
interiorGapPercent - The interior gap (space for labels) as a percentage of the available space.
circular - Flag indicating whether the pie chart is circular or elliptical.
radiusPercent - The radius of the pie chart, as a percentage of the available space (after accounting for interior gap).
sectionLabelFont - The font for the section labels.
sectionLabelPaint - The color for the section labels.
sectionLabelGapPercent - The space between the pie sections and the labels.
Method Detail

getLegendItemLabels

public java.util.List getLegendItemLabels()
Returns a list of labels for the legend.

Specified by:
getLegendItemLabels in class Plot
Returns:
A list of labels.

getInteriorGapPercent

public double getInteriorGapPercent()
Returns the interior gap, measures as a percentage of the available drawing space.

Returns:
The interior gap, measured as a percentage of the available drawing space.

setInteriorGapPercent

public void setInteriorGapPercent(double percent)
Sets the interior gap percent.


isCircular

public boolean isCircular()
Returns a flag indicating whether the pie chart is circular, or stretched into an elliptical shape.

Returns:
A flag indicating whether the pie chart is circular.

setCircular

public void setCircular(boolean flag)
A flag indicating whether the pie chart is circular, or stretched into an elliptical shape.

Parameters:
flag - The new value.

getRadiusPercent

public double getRadiusPercent()
Returns the radius percentage.

Returns:
The radius percentage.

setRadiusPercent

public void setRadiusPercent(double percent)
Sets the radius percentage.

Parameters:
percent - The new value.

getSectionLabelType

public int getSectionLabelType()
Returns the section label type. Defined by the constants: NO_LABELS, NAME_LABELS, PERCENT_LABELS and NAME_AND_PERCENT_LABELS.

Returns:
The section label type.

setSectionLabelType

public void setSectionLabelType(int type)
Sets the section label type.

Valid types are defined by the following constants: NO_LABELS, NAME_LABELS, PERCENT_LABELS, NAME_AND_PERCENT_LABELS.


getSectionLabelFont

public java.awt.Font getSectionLabelFont()
Returns the section label font.

Returns:
The section label font.

setSectionLabelFont

public void setSectionLabelFont(java.awt.Font font)
Sets the section label font.

Notifies registered listeners that the plot has been changed.

Parameters:
font - The new section label font.

getSectionLabelPaint

public java.awt.Paint getSectionLabelPaint()
Returns the section label paint.

Returns:
The section label paint.

setSectionLabelPaint

public void setSectionLabelPaint(java.awt.Paint paint)
Sets the section label paint.

Notifies registered listeners that the plot has been changed.

Parameters:
paint - The new section label paint.

getSectionLabelGapPercent

public double getSectionLabelGapPercent()
Returns the section label gap, measures as a percentage of the radius.

Returns:
The section label gap, measures as a percentage of the radius.

setSectionLabelGapPercent

public void setSectionLabelGapPercent(double percent)
Sets the section label gap percent.


setValueFormatString

public void setValueFormatString(java.lang.String format)
Sets the format string for the value labels.


setPercentFormatString

public void setPercentFormatString(java.lang.String format)
Sets the format string for the percent labels.


getExplodePercent

public double getExplodePercent(int section)
Returns the amount that a section should be 'exploded'.

Parameters:
section - The section number.

setExplodePercent

public void setExplodePercent(int section,
                              double percent)
Sets the amount that a pie section should be exploded.


getPieDataset

public PieDataset getPieDataset()
Returns the dataset for the plot, cast as a PieDataset.

Provided for convenience.

Returns:
The dataset for the plot, cast as a PieDataset.

getCategories

public java.util.Collection getCategories()
Returns a collection of the categories in the dataset.

Returns:
The categories.

getToolTipGenerator

public com.jrefinery.chart.tooltips.PieToolTipGenerator getToolTipGenerator()
Returns the tooltip generator (possibly null).


setToolTipGenerator

public void setToolTipGenerator(com.jrefinery.chart.tooltips.PieToolTipGenerator generator)
Sets the tooltip generator.

Parameters:
generator - The new tooltip generator (null permitted).

draw

public void draw(java.awt.Graphics2D g2,
                 java.awt.geom.Rectangle2D plotArea,
                 ChartRenderingInfo info)
Draws the plot on a Java 2D graphics device (such as the screen or a printer).

Specified by:
draw in class Plot
Parameters:
g2 - The graphics device.
plotArea - The area within which the plot should be drawn.
info - Collects info about the drawing.

drawLabel

protected void drawLabel(java.awt.Graphics2D g2,
                         java.awt.geom.Rectangle2D pieArea,
                         java.awt.geom.Rectangle2D explodedPieArea,
                         PieDataset data,
                         double value,
                         int section,
                         double startAngle,
                         double extent)
Draws the label for one pie section. You can set the plot up for different types of labels using the setSectionLabelType() method. Available types are: NO_LABELS, NAME_LABELS, PERCENT_LABELS and NAME_AND_PERCENT_LABELS.

Parameters:
g2 - The graphics device.
pieArea - The area for the unexploded pie sections.
explodedPieArea - The area for the exploded pie section.
data - The data for the plot.
section - The section (zero-based index).
startAngle - The starting angle.
extent - The extent of the arc.

getPlotType

public java.lang.String getPlotType()
Returns a short string describing the type of plot.

Specified by:
getPlotType in class Plot
Returns:
A short string describing the plot type.

isCompatibleHorizontalAxis

public boolean isCompatibleHorizontalAxis(Axis axis)
Returns true if the axis is compatible with the pie plot, and false otherwise. Since a pie plot requires no axes, only a null axis is compatible.

Parameters:
axis - The axis.

isCompatibleVerticalAxis

public boolean isCompatibleVerticalAxis(Axis axis)
Returns true if the axis is compatible with the pie plot, and false otherwise. Since a pie plot requires no axes, only a null axis is compatible.

Parameters:
axis - The axis.

zoom

public void zoom(double percent)
A zoom method that does nothing.

Plots are required to support the zoom operation. In the case of a pie chart, it doesn't make sense to zoom in or out, so the method is empty.

Specified by:
zoom in class Plot
Parameters:
percent - The zoom percentage.

getArcBounds

protected java.awt.geom.Rectangle2D getArcBounds(java.awt.geom.Rectangle2D unexploded,
                                                 java.awt.geom.Rectangle2D exploded,
                                                 double startAngle,
                                                 double extent,
                                                 double explodePercent)
Returns a rectangle that can be used to create a pie section (taking into account the amount by which the pie section is 'exploded').

Parameters:
unexploded - The area inside which the unexploded pie sections are drawn.
exploded - The area inside which the exploded pie sections are drawn.
startAngle - The start angle.
extent - The extent of the arc.
explodePercent - The amount by which the pie section is exploded.

calculateLabelLocation

protected java.awt.geom.Point2D calculateLabelLocation(java.awt.geom.Rectangle2D labelBounds,
                                                       double ascent,
                                                       java.awt.geom.Rectangle2D unexploded,
                                                       java.awt.geom.Rectangle2D exploded,
                                                       double startAngle,
                                                       double extent,
                                                       double explodePercent)
Returns the location for a label, taking into account whether or not the pie section is exploded.

Parameters:
labelBounds - The label bounds.
ascent - The ascent.
unexploded - The area within which the unexploded pie sections are drawn.
exploded - The area within which the exploded pie sections are drawn.
startAngle - The start angle for the pie section.
extent - The extent of the arc.
explodePercent - The amount by which the pie section is exploded.


Copyright © 2003 MBARI.

The Monterey Bay Aquarium Research Institute (MBARI) provides this documentation and code "as is", with no warranty, express or implied, of its quality or consistency. It is provided without support and without obligation on the part of MBARI to assist in its use, correction, modification, or enhancement.