com.jrefinery.chart
Class Plot

java.lang.Object
  |
  +--com.jrefinery.chart.Plot
All Implemented Interfaces:
AxisChangeListener, AxisConstants, DatasetChangeListener, java.util.EventListener
Direct Known Subclasses:
CategoryPlot, CompassPlot, FastScatterPlot, MeterPlot, PiePlot, ThermometerPlot, XYPlot

public abstract class Plot
extends java.lang.Object
implements AxisChangeListener, DatasetChangeListener, AxisConstants

The base class for all plots in JFreeChart. The JFreeChart class delegates the drawing of axes and data to the plot. This base class provides facilities common to most plot types.

Author:
DG

Field Summary
protected  float backgroundAlpha
          The alpha transparency for the background paint.
protected  java.awt.Image backgroundImage
          An optional image for the plot background.
protected  java.awt.Paint backgroundPaint
          An optional color used to fill the plot background.
protected  Dataset dataset
          The data.
protected static float DEFAULT_BACKGROUND_ALPHA
          The default background alpha transparency.
protected static java.awt.Paint DEFAULT_BACKGROUND_PAINT
          The default background color.
protected static float DEFAULT_FOREGROUND_ALPHA
          The default foreground alpha transparency.
protected static java.awt.Insets DEFAULT_INSETS
          The default insets.
protected static java.awt.Paint DEFAULT_OUTLINE_PAINT
          The default outline color.
protected static java.awt.Stroke DEFAULT_OUTLINE_STROKE
          The default outline stroke.
protected  float foregroundAlpha
          The alpha-transparency for the plot.
protected  java.awt.Insets insets
          Amount of blank space around the plot area.
protected  javax.swing.event.EventListenerList listenerList
          Storage for registered change listeners.
protected static int MINIMUM_HEIGHT_TO_DRAW
          The minimum height for the plot, any less space than this and it should not be drawn (not fully implemented.
protected static int MINIMUM_WIDTH_TO_DRAW
          The minimum width for the plot, any less space than this and it should not be drawn (not fully implemented).
protected  java.lang.String noDataMessage
          The message to display if no data is available.
protected  java.awt.Font noDataMessageFont
          The font used to display the 'no data' message.
protected  java.awt.Paint outlinePaint
          The Paint used to draw an outline around the plot.
protected  java.awt.Stroke outlineStroke
          The Stroke used to draw an outline around the plot.
protected  java.awt.Paint[] seriesOutlinePaint
          Paint objects used to draw the outline of each series in the chart.
protected  java.awt.Stroke[] seriesOutlineStroke
          Stroke objects used to draw the outline of each series in the chart.
protected  java.awt.Paint[] seriesPaint
          Paint objects used to color each series in the chart.
protected  java.awt.Stroke[] seriesStroke
          Stroke objects used to draw each series in the chart.
protected  ShapeFactory shapeFactory
          Factory for shapes used to represent data points
static java.lang.Number ZERO
          Useful constant representing 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_PAINT, DEFAULT_TICK_STROKE
 
Constructor Summary
protected Plot(Dataset data)
          Constructs a new plot with the specified axes.
protected Plot(Dataset 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)
          Constructs a new plot.
 
Method Summary
 void addChangeListener(PlotChangeListener listener)
          Registers an object for notification of changes to the plot.
 void axisChanged(AxisChangeEvent event)
          Receives notification of a change to one of the plot's axes.
 void datasetChanged(DatasetChangeEvent event)
          Receives notification of a change to the plot's dataset.
abstract  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 drawNoDataMessage(java.awt.Graphics2D g2, java.awt.geom.Rectangle2D area)
          Draws a message to state that there is no data to plot.
 void drawOutlineAndBackground(java.awt.Graphics2D g2, java.awt.geom.Rectangle2D area)
          Draw the plot outline and background.
 float getBackgroundAlpha()
          Returns the alpha transparency of the plot area background.
 java.awt.Paint getBackgroundPaint()
          Returns the background color of the plot area.
 Dataset getDataset()
          Returns the dataset for the plot.
 DatasetGroup getDatasetGroup()
          Returns the dataset group for the plot.
 float getForegroundAlpha()
          Returns the alpha-transparency for the plot foreground.
 java.awt.Insets getInsets()
          Returns the insets for the plot area.
 java.util.List getLegendItemLabels()
          Deprecated. use getLegendItems().
 LegendItemCollection getLegendItems()
          Returns the legend items for the plot.
 java.lang.String getNoDataMessage()
          Returns the string that is displayed when the dataset is empty or null.
 java.awt.Font getNoDataMessageFont()
          Returns the font used to display the 'no data' message.
 java.awt.Paint getOutlinePaint()
          Returns the color used to draw the outline of the plot area.
 java.awt.Stroke getOutlineStroke()
          Returns the pen/brush used to outline the plot area.
abstract  java.lang.String getPlotType()
          Returns a short string describing the plot type.
 java.awt.Paint getSeriesOutlinePaint(int index)
          Returns the Paint used to outline any shapes for the specified series.
 java.awt.Stroke getSeriesOutlineStroke(int index)
          Returns the Stroke used to outline any shapes for the specified series.
 java.awt.Paint getSeriesPaint(int index)
          Returns a Paint object used as the main color for a series.
 java.awt.Stroke getSeriesStroke(int index)
          Returns the Stroke used to draw any shapes for a series.
 java.awt.Shape getShape(int series, int item, double x, double y, double scale)
          Returns a Shape that can be used in plotting data.
 java.awt.Shape getShape(int series, java.lang.Object category, double x, double y, double scale)
          Returns a Shape that can be used in plotting data.
 ShapeFactory getShapeFactory()
          Returns the object used to generate shapes for marking data points.
 void handleClick(int x, int y, ChartRenderingInfo info)
          Handles a 'click' on the plot.
 boolean isSubplot()
          Returns true if this plot is part of a combined plot structure.
 void notifyListeners(PlotChangeEvent event)
          Notifies all registered listeners that the plot has been modified.
 void removeChangeListener(PlotChangeListener listener)
          Unregisters an object for notification of changes to the plot.
 void setBackgroundAlpha(float alpha)
          Sets the alpha transparency of the plot area background, and notifies registered listeners that the plot has been modified.
 void setBackgroundImage(java.awt.Image image)
          Sets the background image for the plot.
 void setBackgroundPaint(java.awt.Paint paint)
          Sets the background color of the plot area, and notifies registered listeners that the plot has been modified.
 void setDataset(Dataset data)
          Sets the data for the chart, replacing any existing data.
protected  void setDatasetGroup(DatasetGroup group)
          Sets the dataset group.
 void setForegroundAlpha(float alpha)
          Sets the alpha-transparency for the plot.
 void setInsets(java.awt.Insets insets)
          Sets the insets for the plot and notifies registered listeners that the plot has been modified.
 void setNoDataMessage(java.lang.String message)
          Sets the message that is displayed when the dataset is empty or null.
 void setNoDataMessageFont(java.awt.Font font)
          Sets the font used to display the 'no data' message.
 void setOutlinePaint(java.awt.Paint paint)
          Sets the color of the outline of the plot area, and notifies registered listeners that the Plot has been modified.
 void setOutlineStroke(java.awt.Stroke stroke)
          Sets the pen/brush used to outline the plot area, and notifies registered listeners that the plot has been modified.
 void setSeriesOutlinePaint(java.awt.Paint[] paint)
          Sets the paint used to outline any shapes representing series, and notifies registered listeners that the chart has been modified.
 void setSeriesOutlineStroke(int index, java.awt.Stroke stroke)
          Sets the stroke used to draw any shapes representing a specific series, and notifies registered listeners that the chart has been modified.
 void setSeriesOutlineStroke(java.awt.Stroke[] stroke)
          Sets the stroke used to draw any shapes representing series, and notifies registered listeners that the chart has been modified.
 void setSeriesPaint(int index, java.awt.Paint paint)
          Sets the paint used to color any shapes representing a specific series, and notifies registered listeners that the plot has been modified.
 void setSeriesPaint(java.awt.Paint[] paint)
          Sets the paint used to color any shapes representing series, and notifies registered listeners that the plot has been modified.
 void setSeriesStroke(int index, java.awt.Stroke stroke)
          Sets the stroke used to draw any shapes representing a specific series, and notifies registered listeners that the chart has been modified.
 void setSeriesStroke(java.awt.Stroke[] stroke)
          Sets the stroke used to draw any shapes representing series, and notifies registered listeners that the chart has been modified.
 void setShapeFactory(ShapeFactory factory)
          Sets the object used to generate shapes for marking data points.
 void zoom(double percent)
          Performs a zoom on the plot.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

ZERO

public static final java.lang.Number ZERO
Useful constant representing zero.

DEFAULT_INSETS

protected static final java.awt.Insets DEFAULT_INSETS
The default insets.

DEFAULT_OUTLINE_STROKE

protected static final java.awt.Stroke DEFAULT_OUTLINE_STROKE
The default outline stroke.

DEFAULT_OUTLINE_PAINT

protected static final java.awt.Paint DEFAULT_OUTLINE_PAINT
The default outline color.

DEFAULT_FOREGROUND_ALPHA

protected static final float DEFAULT_FOREGROUND_ALPHA
The default foreground alpha transparency.

DEFAULT_BACKGROUND_ALPHA

protected static final float DEFAULT_BACKGROUND_ALPHA
The default background alpha transparency.

DEFAULT_BACKGROUND_PAINT

protected static final java.awt.Paint DEFAULT_BACKGROUND_PAINT
The default background color.

MINIMUM_WIDTH_TO_DRAW

protected static final int MINIMUM_WIDTH_TO_DRAW
The minimum width for the plot, any less space than this and it should not be drawn (not fully implemented).

MINIMUM_HEIGHT_TO_DRAW

protected static final int MINIMUM_HEIGHT_TO_DRAW
The minimum height for the plot, any less space than this and it should not be drawn (not fully implemented.

dataset

protected Dataset dataset
The data.

noDataMessage

protected java.lang.String noDataMessage
The message to display if no data is available.

noDataMessageFont

protected java.awt.Font noDataMessageFont
The font used to display the 'no data' message.

insets

protected java.awt.Insets insets
Amount of blank space around the plot area.

outlineStroke

protected java.awt.Stroke outlineStroke
The Stroke used to draw an outline around the plot.

outlinePaint

protected java.awt.Paint outlinePaint
The Paint used to draw an outline around the plot.

backgroundPaint

protected java.awt.Paint backgroundPaint
An optional color used to fill the plot background.

backgroundImage

protected java.awt.Image backgroundImage
An optional image for the plot background.

foregroundAlpha

protected float foregroundAlpha
The alpha-transparency for the plot.

backgroundAlpha

protected float backgroundAlpha
The alpha transparency for the background paint.

seriesPaint

protected java.awt.Paint[] seriesPaint
Paint objects used to color each series in the chart.

seriesStroke

protected java.awt.Stroke[] seriesStroke
Stroke objects used to draw each series in the chart.

seriesOutlinePaint

protected java.awt.Paint[] seriesOutlinePaint
Paint objects used to draw the outline of each series in the chart.

seriesOutlineStroke

protected java.awt.Stroke[] seriesOutlineStroke
Stroke objects used to draw the outline of each series in the chart.

shapeFactory

protected ShapeFactory shapeFactory
Factory for shapes used to represent data points

listenerList

protected javax.swing.event.EventListenerList listenerList
Storage for registered change listeners.
Constructor Detail

Plot

protected Plot(Dataset data)
Constructs a new plot with the specified axes.
Parameters:
data - the dataset.

Plot

protected Plot(Dataset 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)
Constructs a new plot.
Parameters:
data - the dataset.
insets - the 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 foreground.
Method Detail

getDataset

public Dataset getDataset()
Returns the dataset for the plot.
Returns:
the dataset.

setDataset

public void setDataset(Dataset data)
Sets the data for the chart, replacing any existing data. Registered listeners are notified that the data has been modified.

The plot is automatically registered with the new dataset, to listen for any changes.

Parameters:
data - the new dataset.

getDatasetGroup

public DatasetGroup getDatasetGroup()
Returns the dataset group for the plot.

setDatasetGroup

protected void setDatasetGroup(DatasetGroup group)
Sets the dataset group.
Parameters:
group - the dataset group.

getNoDataMessage

public java.lang.String getNoDataMessage()
Returns the string that is displayed when the dataset is empty or null.
Returns:
the 'no data' message (null possible).

setNoDataMessage

public void setNoDataMessage(java.lang.String message)
Sets the message that is displayed when the dataset is empty or null.
Parameters:
message - the message (null permitted).

getNoDataMessageFont

public java.awt.Font getNoDataMessageFont()
Returns the font used to display the 'no data' message.
Returns:
the font.

setNoDataMessageFont

public void setNoDataMessageFont(java.awt.Font font)
Sets the font used to display the 'no data' message.
Parameters:
font - the font.

getPlotType

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

Note: this gets used in the chart property editing user interface, but there needs to be a better mechanism for identifying the plot type.

Returns:
a short string describing the plot type.

isSubplot

public boolean isSubplot()
Returns true if this plot is part of a combined plot structure.
Returns:
a flag indicating if this plot is a subplot.

getInsets

public java.awt.Insets getInsets()
Returns the insets for the plot area.
Returns:
the insets.

setInsets

public void setInsets(java.awt.Insets insets)
Sets the insets for the plot and notifies registered listeners that the plot has been modified.
Parameters:
insets - the new insets.

getBackgroundPaint

public java.awt.Paint getBackgroundPaint()
Returns the background color of the plot area.
Returns:
the background color (null possible).

setBackgroundPaint

public void setBackgroundPaint(java.awt.Paint paint)
Sets the background color of the plot area, and notifies registered listeners that the plot has been modified.
Parameters:
paint - the new background color (null permitted).

getBackgroundAlpha

public float getBackgroundAlpha()
Returns the alpha transparency of the plot area background.
Returns:
the alpha transparency.

setBackgroundAlpha

public void setBackgroundAlpha(float alpha)
Sets the alpha transparency of the plot area background, and notifies registered listeners that the plot has been modified.
Parameters:
alpha - the new alpha value.

setBackgroundImage

public void setBackgroundImage(java.awt.Image image)
Sets the background image for the plot.
Parameters:
image - the background image.

getOutlineStroke

public java.awt.Stroke getOutlineStroke()
Returns the pen/brush used to outline the plot area.
Returns:
the outline stroke (possibly null).

setOutlineStroke

public void setOutlineStroke(java.awt.Stroke stroke)
Sets the pen/brush used to outline the plot area, and notifies registered listeners that the plot has been modified.
Parameters:
stroke - the new outline pen/brush (null permitted).

getOutlinePaint

public java.awt.Paint getOutlinePaint()
Returns the color used to draw the outline of the plot area.
Returns:
the color (possibly null).

setOutlinePaint

public void setOutlinePaint(java.awt.Paint paint)
Sets the color of the outline of the plot area, and notifies registered listeners that the Plot has been modified.
Parameters:
paint - the new outline paint (null permitted).

getForegroundAlpha

public float getForegroundAlpha()
Returns the alpha-transparency for the plot foreground.
Returns:
the alpha-transparency.

setForegroundAlpha

public void setForegroundAlpha(float alpha)
Sets the alpha-transparency for the plot.
Parameters:
alpha - the new alpha transparency.

getLegendItemLabels

public java.util.List getLegendItemLabels()
Deprecated. use getLegendItems().

Returns a list of labels for the legend.

Most plots will return a list of series names, but there are some plots (e.g. PiePlot) that do not have series so they will return something else.

Returns:
the series labels.

getLegendItems

public LegendItemCollection getLegendItems()
Returns the legend items for the plot.

By default, this method returns null. Subclasses should override to return a collection of legend items.

Returns:
the legend items for the plot.

getSeriesPaint

public java.awt.Paint getSeriesPaint(int index)
Returns a Paint object used as the main color for a series.
Parameters:
index - the series index (zero-based).
Returns:
a Paint object used as the main color for a series.

setSeriesPaint

public void setSeriesPaint(java.awt.Paint[] paint)
Sets the paint used to color any shapes representing series, and notifies registered listeners that the plot has been modified.
Parameters:
paint - an array of Paint objects used to color series.

setSeriesPaint

public void setSeriesPaint(int index,
                           java.awt.Paint paint)
Sets the paint used to color any shapes representing a specific series, and notifies registered listeners that the plot has been modified.
Parameters:
index - the series (zero-based index).
paint - an array of Paint objects used to color series.

getSeriesStroke

public java.awt.Stroke getSeriesStroke(int index)
Returns the Stroke used to draw any shapes for a series.
Parameters:
index - the series (zero-based index).
Returns:
the Stroke used to draw any shapes for a series.

setSeriesStroke

public void setSeriesStroke(java.awt.Stroke[] stroke)
Sets the stroke used to draw any shapes representing series, and notifies registered listeners that the chart has been modified.
Parameters:
stroke - an array of Stroke objects used to draw series.

setSeriesStroke

public void setSeriesStroke(int index,
                            java.awt.Stroke stroke)
Sets the stroke used to draw any shapes representing a specific series, and notifies registered listeners that the chart has been modified.
Parameters:
index - the series (zero-based index)
stroke - an array of Stroke objects used to draw series.

getSeriesOutlinePaint

public java.awt.Paint getSeriesOutlinePaint(int index)
Returns the Paint used to outline any shapes for the specified series.
Parameters:
index - the series (zero-based index).
Returns:
the Paint.

setSeriesOutlinePaint

public void setSeriesOutlinePaint(java.awt.Paint[] paint)
Sets the paint used to outline any shapes representing series, and notifies registered listeners that the chart has been modified.
Parameters:
paint - an array of Paint objects for drawing the outline of series shapes.

getSeriesOutlineStroke

public java.awt.Stroke getSeriesOutlineStroke(int index)
Returns the Stroke used to outline any shapes for the specified series.
Parameters:
index - the series (zero-based index).
Returns:
the Stroke used to outline any shapes for the specified series.

setSeriesOutlineStroke

public void setSeriesOutlineStroke(java.awt.Stroke[] stroke)
Sets the stroke used to draw any shapes representing series, and notifies registered listeners that the chart has been modified.
Parameters:
stroke - an array of Stroke objects.

setSeriesOutlineStroke

public void setSeriesOutlineStroke(int index,
                                   java.awt.Stroke stroke)
Sets the stroke used to draw any shapes representing a specific series, and notifies registered listeners that the chart has been modified.
Parameters:
index - the series index (zero-based).
stroke - an array of Stroke objects.

getShapeFactory

public ShapeFactory getShapeFactory()
Returns the object used to generate shapes for marking data points.
Returns:
the object used to generate shapes for marking data points.

setShapeFactory

public void setShapeFactory(ShapeFactory factory)
Sets the object used to generate shapes for marking data points.
Parameters:
factory - the new shape factory.

getShape

public java.awt.Shape getShape(int series,
                               int item,
                               double x,
                               double y,
                               double scale)
Returns a Shape that can be used in plotting data. Used in XYPlots.
Parameters:
series - the index of the series.
item - the index of the item.
x - x-coordinate of the item.
y - y-coordinate of the item.
scale - the size.
Returns:
a Shape that can be used in plotting data.

getShape

public java.awt.Shape getShape(int series,
                               java.lang.Object category,
                               double x,
                               double y,
                               double scale)
Returns a Shape that can be used in plotting data. Should allow a plug-in object to determine the shape...
Parameters:
series - the index of the series.
category - the category.
x - x-coordinate of the category.
y - y-coordinate of the category.
scale - the size.
Returns:
a Shape that can be used in plotting data.

addChangeListener

public void addChangeListener(PlotChangeListener listener)
Registers an object for notification of changes to the plot.
Parameters:
listener - the object to be registered.

removeChangeListener

public void removeChangeListener(PlotChangeListener listener)
Unregisters an object for notification of changes to the plot.
Parameters:
listener - the object to be unregistered.

notifyListeners

public void notifyListeners(PlotChangeEvent event)
Notifies all registered listeners that the plot has been modified.
Parameters:
event - information about the change event.

draw

public abstract 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).

This class does not store any information about where the individual items that make up the plot are actually drawn. If you want to collect this information, pass in a ChartRenderingInfo object. After the drawing is complete, the info object will contain lots of information about the chart. If you don't want the information, pass in null. *

Parameters:
g2 - the graphics device.
plotArea - the area within which the plot should be drawn.
info - an object for collecting information about the drawing of the chart.

drawOutlineAndBackground

public void drawOutlineAndBackground(java.awt.Graphics2D g2,
                                     java.awt.geom.Rectangle2D area)
Draw the plot outline and background.
Parameters:
g2 - the graphics device.
area - the area within which the plot should be drawn.

drawNoDataMessage

protected void drawNoDataMessage(java.awt.Graphics2D g2,
                                 java.awt.geom.Rectangle2D area)
Draws a message to state that there is no data to plot.
Parameters:
g2 - the graphics device.
area - the area within which the plot should be drawn.

handleClick

public void handleClick(int x,
                        int y,
                        ChartRenderingInfo info)
Handles a 'click' on the plot. Since the plot does not maintain any information about where it has been drawn, the plot area is supplied as an argument.
Parameters:
x - the x coordinate.
y - the y coordinate.
info - an object for collecting information about the drawing of the chart.

zoom

public void zoom(double percent)
Performs a zoom on the plot. Subclasses should override if zooming is appropriate for the type of plot.
Parameters:
percent - the zoom percentage.

axisChanged

public void axisChanged(AxisChangeEvent event)
Receives notification of a change to one of the plot's axes.
Specified by:
axisChanged in interface AxisChangeListener
Parameters:
event - information about the event (not used here).

datasetChanged

public void datasetChanged(DatasetChangeEvent event)
Receives notification of a change to the plot's dataset.

The plot reacts by passing on a plot change event to all registered listeners.

Specified by:
datasetChanged in interface DatasetChangeListener
Parameters:
event - information about the event (not used here).