org.jfree.chart.plot
Class CategoryPlot

java.lang.Object
  |
  +--org.jfree.chart.plot.Plot
        |
        +--org.jfree.chart.plot.CategoryPlot
All Implemented Interfaces:
AxisChangeListener, AxisConstants, CategoryPlotConstants, DatasetChangeListener, java.util.EventListener, java.io.Serializable
Direct Known Subclasses:
HorizontalCategoryPlot, VerticalCategoryPlot

public abstract class CategoryPlot
extends Plot
implements CategoryPlotConstants, java.io.Serializable

A general plotting class that uses data from a CategoryDataset and renders each data item using a CategoryItemRenderer.

Author:
David Gilbert
See Also:
Serialized Form

Field Summary
 
Fields inherited from class org.jfree.chart.plot.Plot
DEFAULT_BACKGROUND_ALPHA, DEFAULT_BACKGROUND_PAINT, DEFAULT_FOREGROUND_ALPHA, DEFAULT_INSETS, DEFAULT_OUTLINE_PAINT, DEFAULT_OUTLINE_STROKE, MINIMUM_HEIGHT_TO_DRAW, MINIMUM_WIDTH_TO_DRAW, ZERO
 
Fields inherited from interface org.jfree.chart.plot.CategoryPlotConstants
DEFAULT_DOMAIN_GRIDLINES_VISIBLE, DEFAULT_GRIDLINE_PAINT, DEFAULT_GRIDLINE_STROKE, DEFAULT_RANGE_GRIDLINES_VISIBLE, DEFAULT_VALUE_LABEL_FONT
 
Fields inherited from interface org.jfree.chart.axis.AxisConstants
BOTTOM, DEFAULT_AXIS_LABEL_FONT, DEFAULT_AXIS_LABEL_INSETS, DEFAULT_AXIS_LABEL_PAINT, DEFAULT_AXIS_VISIBLE, DEFAULT_TICK_LABEL_FONT, DEFAULT_TICK_LABEL_INSETS, DEFAULT_TICK_LABEL_PAINT, DEFAULT_TICK_LABELS_VISIBLE, DEFAULT_TICK_MARK_INSIDE_LENGTH, DEFAULT_TICK_MARK_OUTSIDE_LENGTH, DEFAULT_TICK_MARK_PAINT, DEFAULT_TICK_MARK_STROKE, DEFAULT_TICK_MARKS_VISIBLE, LEFT, RIGHT, TOP
 
Constructor Summary
protected CategoryPlot(CategoryDataset data, CategoryAxis domainAxis, ValueAxis rangeAxis, CategoryItemRenderer renderer)
          Constructs a category plot, using default values where necessary.
 
Method Summary
 void addAnnotation(CategoryAnnotation annotation)
          Adds an annotation to the plot.
 void addRangeMarker(Marker marker)
          Adds a marker for display against the range axis.
 void clearRangeMarkers()
          Clears all the range markers for the plot.
 void datasetChanged(DatasetChangeEvent event)
          Receives notification of a change to the plot's dataset.
 java.util.List getAnnotations()
          Returns the list of annotations.
 CategoryDataset getCategoryDataset()
          A convenience method that returns the dataset for the plot, cast as a CategoryDataset.
 CategoryAxis getDomainAxis()
          Returns the domain axis for the plot.
 int getDomainAxisLocation()
          Returns the domain axis location.
 java.awt.Paint getDomainGridlinePaint()
          Returns the paint used to draw grid-lines against the domain axis.
 java.awt.Stroke getDomainGridlineStroke()
          Returns the stroke used to draw grid-lines against the domain axis.
 LegendItemCollection getLegendItems()
          Returns the legend items for the plot.
 ValueAxis getRangeAxis()
          Returns the range axis for the plot.
 int getRangeAxisLocation()
          Returns the range axis location.
 java.awt.Paint getRangeCrosshairPaint()
          Returns the range crosshair color.
 java.awt.Stroke getRangeCrosshairStroke()
          Returns the Stroke used to draw the crosshair (if visible).
 double getRangeCrosshairValue()
          Returns the range crosshair value.
 java.awt.Paint getRangeGridlinePaint()
          Returns the paint used to draw the grid-lines against the range axis.
 java.awt.Stroke getRangeGridlineStroke()
          Returns the stroke used to draw the grid-lines against the range axis.
 java.util.List getRangeMarkers()
          Returns the list of range markers.
 CategoryItemRenderer getRenderer()
          Returns a reference to the renderer for the plot.
 CategoryDataset getSecondaryCategoryDataset()
          Returns the secondary dataset, cast as a CategoryDataset.
 ValueAxis getSecondaryRangeAxis()
          Returns the (optional) secondary range axis.
 CategoryItemRenderer getSecondaryRenderer()
          Returns the renderer used to draw data items from the secondary dataset.
 java.awt.Font getValueLabelFont()
          Returns the value label font.
 java.text.NumberFormat getValueLabelFormatter()
          Returns the value label formatter.
 java.awt.Paint getValueLabelPaint()
          Returns the value label paint.
 boolean getValueLabelsVisible()
          Returns a flag that indicates whether or not the value labels are showing.
 boolean getVerticalValueLabels()
          Returns true if the value labels should be rotated to vertical, and false for standard horizontal labels.
abstract  boolean isCompatibleDomainAxis(CategoryAxis axis)
          Checks the compatibility of a domain axis, returning true if the axis is compatible with the plot, and false otherwise.
abstract  boolean isCompatibleRangeAxis(ValueAxis axis)
          Checks the compatibility of a range axis, returning true if the axis is compatible with the plot, and false otherwise.
 boolean isDomainGridlinesVisible()
          Returns the flag that controls whether the domain grid-lines are visible.
 boolean isRangeCrosshairLockedOnData()
          Returns a flag indicating whether or not the crosshair should "lock-on" to actual data values.
 boolean isRangeCrosshairVisible()
          Returns a flag indicating whether or not the range crosshair is visible.
 boolean isRangeGridlinesVisible()
          Returns the flag that controls whether the range grid-lines are visible.
 void setDomainAxis(CategoryAxis axis)
          Sets the domain axis for the plot (this must be compatible with the plot type or an exception is thrown).
 void setDomainAxisLocation(int location)
          Sets the location of the domain axis.
 void setDomainAxisLocation(int location, boolean notify)
          Sets the location of the domain axis.
 void setDomainGridlinePaint(java.awt.Paint paint)
          Sets the paint used to draw the grid-lines (if any) against the domain axis.
 void setDomainGridlineStroke(java.awt.Stroke stroke)
          Sets the stroke used to draw grid-lines against the domain axis.
 void setDomainGridlinesVisible(boolean visible)
          Sets the flag that controls whether or not grid-lines are drawn against the domain axis.
 void setLabelsVisible(boolean flag)
          Deprecated. use setValueLabelsVisible(boolean).
 void setRangeAxis(ValueAxis axis)
          Sets the range axis for the plot.
 void setRangeAxisLocation(int location)
          Sets the location of the range axis.
 void setRangeAxisLocation(int location, boolean notify)
          Sets the location of the range axis.
 void setRangeCrosshairLockedOnData(boolean flag)
          Sets the flag indicating whether or not the range crosshair should "lock-on" to actual data values.
 void setRangeCrosshairPaint(java.awt.Paint paint)
          Sets the Paint used to color the crosshairs (if visible) and notifies registered listeners that the axis has been modified.
 void setRangeCrosshairStroke(java.awt.Stroke stroke)
          Sets the Stroke used to draw the crosshairs (if visible) and notifies registered listeners that the axis has been modified.
 void setRangeCrosshairValue(double value)
          Sets the domain crosshair value.
 void setRangeCrosshairValue(double value, boolean notify)
          Sets the range crosshair value.
 void setRangeCrosshairVisible(boolean flag)
          Sets the flag indicating whether or not the range crosshair is visible.
 void setRangeGridlinePaint(java.awt.Paint paint)
          Sets the paint used to draw the grid lines against the range axis.
 void setRangeGridlineStroke(java.awt.Stroke stroke)
          Sets the stroke used to draw the grid-lines against the range axis.
 void setRangeGridlinesVisible(boolean visible)
          Sets the flag that controls whether or not grid-lines are drawn against the range axis.
 void setRenderer(CategoryItemRenderer renderer)
          Sets the renderer for the plot.
 void setRenderer(CategoryItemRenderer renderer, boolean notify)
          Sets the renderer for the plot.
 void setSecondaryRangeAxis(ValueAxis axis)
          Sets the secondary range axis.
 void setSecondaryRenderer(CategoryItemRenderer renderer)
          Sets the renderer used to draw data items from the secondary dataset.
 void setValueLabelFont(java.awt.Font font)
          Sets the value label font.
 void setValueLabelFormatString(java.lang.String format)
          Sets the format string for the value labels.
 void setValueLabelPaint(java.awt.Paint paint)
          Sets the value label paint.
 void setValueLabelsVisible(boolean flag)
          Sets the flag that indicates whether or not the value labels are showing.
 void setVerticalValueLabels(boolean flag)
          Sets the flag that determines the orientation of the value labels.
 void zoom(double percent)
          Zooms (in or out) on the plot's value axis.
 
Methods inherited from class org.jfree.chart.plot.Plot
addChangeListener, axisChanged, draw, drawBackground, drawNoDataMessage, drawOutline, equals, getBackgroundAlpha, getBackgroundImage, getBackgroundImageAlignment, getBackgroundPaint, getDataAreaRatio, getDataset, getDatasetGroup, getForegroundAlpha, getInsets, getNoDataMessage, getNoDataMessageFont, getNoDataMessagePaint, getOppositeAxisLocation, getOutlinePaint, getOutlineStroke, getParent, getPlotType, getRectX, getRectY, getRootPlot, getSecondaryDataset, handleClick, isSubplot, notifyListeners, removeChangeListener, setBackgroundAlpha, setBackgroundImage, setBackgroundImageAlignment, setBackgroundPaint, setDataAreaRatio, setDataset, setDatasetGroup, setForegroundAlpha, setInsets, setInsets, setNoDataMessage, setNoDataMessageFont, setNoDataMessagePaint, setOutlinePaint, setOutlineStroke, setParent, setSecondaryDataset
 
Methods inherited from class java.lang.Object
clone, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

CategoryPlot

protected CategoryPlot(CategoryDataset data,
                       CategoryAxis domainAxis,
                       ValueAxis rangeAxis,
                       CategoryItemRenderer renderer)
Constructs a category plot, using default values where necessary.

The domain axis location defaults to BOTTOM and the range axis location defaults to LEFT. These settings are appropriate for a 'vertical' category plot, but must be overridden for a 'horizontal' category plot.

Parameters:
data - the dataset.
domainAxis - the domain axis.
rangeAxis - the range axis.
renderer - the item renderer.
Method Detail

getLegendItems

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

Overrides:
getLegendItems in class Plot
Returns:
the legend items.

getRenderer

public CategoryItemRenderer getRenderer()
Returns a reference to the renderer for the plot.

Returns:
the renderer.

setRenderer

public void setRenderer(CategoryItemRenderer renderer)
Sets the renderer for the plot. A PlotChangeEvent is sent to all registered listeners.

Parameters:
renderer - the renderer.

setRenderer

public void setRenderer(CategoryItemRenderer renderer,
                        boolean notify)
Sets the renderer for the plot.

You can set the renderer to null, but this is not recommended because:

Parameters:
renderer - the renderer (null permitted).
notify - notify listeners?

getCategoryDataset

public CategoryDataset getCategoryDataset()
A convenience method that returns the dataset for the plot, cast as a CategoryDataset.

Returns:
the dataset.

getDomainAxis

public CategoryAxis getDomainAxis()
Returns the domain axis for the plot. If the domain axis for this plot is null, then the method will return the parent plot's domain axis (if there is a parent plot).

Returns:
the domain axis.

setDomainAxis

public void setDomainAxis(CategoryAxis axis)
                   throws AxisNotCompatibleException
Sets the domain axis for the plot (this must be compatible with the plot type or an exception is thrown).

Parameters:
axis - the new axis.
Throws:
AxisNotCompatibleException - if axis are not compatible.

getDomainAxisLocation

public int getDomainAxisLocation()
Returns the domain axis location.

Returns:
the domain axis location.

setDomainAxisLocation

public void setDomainAxisLocation(int location)
Sets the location of the domain axis.

Use one of the constants LEFT, RIGHT, TOP or BOTTOM.

Parameters:
location - the axis location.

setDomainAxisLocation

public void setDomainAxisLocation(int location,
                                  boolean notify)
Sets the location of the domain axis.

Use one of the constants LEFT, RIGHT, TOP or BOTTOM.

Parameters:
location - the axis location.
notify - a flag that controls whether listeners are notified.

getRangeAxis

public ValueAxis getRangeAxis()
Returns the range axis for the plot. If the range axis for this plot is null, then the method will return the parent plot's range axis (if there is a parent plot).

Returns:
the range axis.

setRangeAxis

public void setRangeAxis(ValueAxis axis)
                  throws AxisNotCompatibleException
Sets the range axis for the plot.

An exception is thrown if the new axis and the plot are not mutually compatible.

Parameters:
axis - the new axis.
Throws:
AxisNotCompatibleException - if axis are not compatible.

getRangeAxisLocation

public int getRangeAxisLocation()
Returns the range axis location.

Returns:
the range axis location.

setRangeAxisLocation

public void setRangeAxisLocation(int location)
Sets the location of the range axis.

Use one of the constants LEFT, RIGHT, TOP or BOTTOM.

Parameters:
location - the location.

setRangeAxisLocation

public void setRangeAxisLocation(int location,
                                 boolean notify)
Sets the location of the range axis.

Use one of the constants LEFT, RIGHT, TOP or BOTTOM.

Parameters:
location - the location.
notify - a flag that controls whether listeners are notified.

getSecondaryCategoryDataset

public CategoryDataset getSecondaryCategoryDataset()
Returns the secondary dataset, cast as a CategoryDataset.

Returns:
The secondary dataset (possibly null).

getSecondaryRangeAxis

public ValueAxis getSecondaryRangeAxis()
Returns the (optional) secondary range axis. Data from the secondary dataset is plotted against this axis.

Returns:
The secondary range axis (possibly null).

setSecondaryRangeAxis

public void setSecondaryRangeAxis(ValueAxis axis)
Sets the secondary range axis.

A PlotChangeEvent is sent to all registered listeners.

Parameters:
axis - the axis (null permitted).

getSecondaryRenderer

public CategoryItemRenderer getSecondaryRenderer()
Returns the renderer used to draw data items from the secondary dataset.

Returns:
The secondary renderer.

setSecondaryRenderer

public void setSecondaryRenderer(CategoryItemRenderer renderer)
Sets the renderer used to draw data items from the secondary dataset.

Parameters:
renderer - the renderer.

isDomainGridlinesVisible

public boolean isDomainGridlinesVisible()
Returns the flag that controls whether the domain grid-lines are visible.

Returns:
the true or false.

setDomainGridlinesVisible

public void setDomainGridlinesVisible(boolean visible)
Sets the flag that controls whether or not grid-lines are drawn against the domain axis.

If the flag value changes, a PlotChangeEvent is sent to all registered listeners.

Parameters:
visible - the new value of the flag.

getDomainGridlineStroke

public java.awt.Stroke getDomainGridlineStroke()
Returns the stroke used to draw grid-lines against the domain axis.

Returns:
the stroke.

setDomainGridlineStroke

public void setDomainGridlineStroke(java.awt.Stroke stroke)
Sets the stroke used to draw grid-lines against the domain axis. A PlotChangeEvent is sent to all registered listeners.

Parameters:
stroke - the stroke.

getDomainGridlinePaint

public java.awt.Paint getDomainGridlinePaint()
Returns the paint used to draw grid-lines against the domain axis.

Returns:
the paint.

setDomainGridlinePaint

public void setDomainGridlinePaint(java.awt.Paint paint)
Sets the paint used to draw the grid-lines (if any) against the domain axis. A PlotChangeEvent is sent to all registered listeners.

Parameters:
paint - the paint.

isRangeGridlinesVisible

public boolean isRangeGridlinesVisible()
Returns the flag that controls whether the range grid-lines are visible.

Returns:
the flag.

setRangeGridlinesVisible

public void setRangeGridlinesVisible(boolean visible)
Sets the flag that controls whether or not grid-lines are drawn against the range axis. If the flag changes value, a PlotChangeEvent is sent to all registered listeners.

Parameters:
visible - the new value of the flag.

getRangeGridlineStroke

public java.awt.Stroke getRangeGridlineStroke()
Returns the stroke used to draw the grid-lines against the range axis.

Returns:
the stroke.

setRangeGridlineStroke

public void setRangeGridlineStroke(java.awt.Stroke stroke)
Sets the stroke used to draw the grid-lines against the range axis. A PlotChangeEvent is sent to all registered listeners.

Parameters:
stroke - the stroke.

getRangeGridlinePaint

public java.awt.Paint getRangeGridlinePaint()
Returns the paint used to draw the grid-lines against the range axis.

Returns:
the paint.

setRangeGridlinePaint

public void setRangeGridlinePaint(java.awt.Paint paint)
Sets the paint used to draw the grid lines against the range axis. A PlotChangeEvent is sent to all registered listeners.

Parameters:
paint - the paint.

isCompatibleDomainAxis

public abstract boolean isCompatibleDomainAxis(CategoryAxis axis)
Checks the compatibility of a domain axis, returning true if the axis is compatible with the plot, and false otherwise.

Parameters:
axis - the proposed axis.
Returns:
true if the axis is compatible with the plot.

isCompatibleRangeAxis

public abstract boolean isCompatibleRangeAxis(ValueAxis axis)
Checks the compatibility of a range axis, returning true if the axis is compatible with the plot, and false otherwise.

Parameters:
axis - the proposed axis.
Returns:
true if the axis is compatible with the plot.

zoom

public void zoom(double percent)
Zooms (in or out) on the plot's value axis.

If the value 0.0 is passed in as the zoom percent, the auto-range calculation for the axis is restored (which sets the range to include the minimum and maximum data values, thus displaying all the data).

Overrides:
zoom in class Plot
Parameters:
percent - the zoom amount.

getValueLabelsVisible

public boolean getValueLabelsVisible()
Returns a flag that indicates whether or not the value labels are showing.

Returns:
the flag.

setLabelsVisible

public void setLabelsVisible(boolean flag)
Deprecated. use setValueLabelsVisible(boolean).

Sets the flag that indicates whether or not the value labels are showing.

Registered listeners are notified of a general change to the axis.

Parameters:
flag - the flag.

setValueLabelsVisible

public void setValueLabelsVisible(boolean flag)
Sets the flag that indicates whether or not the value labels are showing.

Registered listeners are notified of a general change to the axis.

Not all renderers support this yet.

Parameters:
flag - the flag.

getValueLabelFont

public java.awt.Font getValueLabelFont()
Returns the value label font.

Returns:
the value label font.

setValueLabelFont

public void setValueLabelFont(java.awt.Font font)
Sets the value label font.

Notifies registered listeners that the plot has been changed.

Parameters:
font - the new value label font.

getValueLabelPaint

public java.awt.Paint getValueLabelPaint()
Returns the value label paint.

Returns:
the value label paint

setValueLabelPaint

public void setValueLabelPaint(java.awt.Paint paint)
Sets the value label paint.

Notifies registered listeners that the plot has been changed.

Parameters:
paint - the new value label paint.

getValueLabelFormatter

public java.text.NumberFormat getValueLabelFormatter()
Returns the value label formatter.

Returns:
the value label formatter

setValueLabelFormatString

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

Notifies registered listeners that the plot has been changed.

Parameters:
format - the new value label format pattern. Use null if labels are not to be shown.

getVerticalValueLabels

public boolean getVerticalValueLabels()
Returns true if the value labels should be rotated to vertical, and false for standard horizontal labels.

Returns:
a flag indicating the orientation of the value labels.

setVerticalValueLabels

public void setVerticalValueLabels(boolean flag)
Sets the flag that determines the orientation of the value labels. Registered listeners are notified that the plot has been changed.

Parameters:
flag - the flag.

datasetChanged

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

The range axis bounds will be recalculated if necessary.

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

addRangeMarker

public void addRangeMarker(Marker marker)
Adds a marker for display against the range axis.

Typically a marker will be drawn by the renderer as a line perpendicular to the range axis, however this is entirely up to the renderer.

Parameters:
marker - the marker.

clearRangeMarkers

public void clearRangeMarkers()
Clears all the range markers for the plot.


getRangeMarkers

public java.util.List getRangeMarkers()
Returns the list of range markers.

Returns:
the list of range markers.

isRangeCrosshairVisible

public boolean isRangeCrosshairVisible()
Returns a flag indicating whether or not the range crosshair is visible.

Returns:
the flag.

setRangeCrosshairVisible

public void setRangeCrosshairVisible(boolean flag)
Sets the flag indicating whether or not the range crosshair is visible.

Parameters:
flag - the new value of the flag.

isRangeCrosshairLockedOnData

public boolean isRangeCrosshairLockedOnData()
Returns a flag indicating whether or not the crosshair should "lock-on" to actual data values.

Returns:
the flag.

setRangeCrosshairLockedOnData

public void setRangeCrosshairLockedOnData(boolean flag)
Sets the flag indicating whether or not the range crosshair should "lock-on" to actual data values.

Parameters:
flag - the flag.

getRangeCrosshairValue

public double getRangeCrosshairValue()
Returns the range crosshair value.

Returns:
The value.

setRangeCrosshairValue

public void setRangeCrosshairValue(double value)
Sets the domain crosshair value.

Registered listeners are notified that the plot has been modified, but only if the crosshair is visible.

Parameters:
value - the new value.

setRangeCrosshairValue

public void setRangeCrosshairValue(double value,
                                   boolean notify)
Sets the range crosshair value.

Registered listeners are notified that the axis has been modified, but only if the crosshair is visible.

Parameters:
value - the new value.
notify - a flag that controls whether or not listeners are notified.

getRangeCrosshairStroke

public java.awt.Stroke getRangeCrosshairStroke()
Returns the Stroke used to draw the crosshair (if visible).

Returns:
the crosshair stroke.

setRangeCrosshairStroke

public void setRangeCrosshairStroke(java.awt.Stroke stroke)
Sets the Stroke used to draw the crosshairs (if visible) and notifies registered listeners that the axis has been modified.

Parameters:
stroke - the new crosshair stroke.

getRangeCrosshairPaint

public java.awt.Paint getRangeCrosshairPaint()
Returns the range crosshair color.

Returns:
the crosshair color.

setRangeCrosshairPaint

public void setRangeCrosshairPaint(java.awt.Paint paint)
Sets the Paint used to color the crosshairs (if visible) and notifies registered listeners that the axis has been modified.

Parameters:
paint - the new crosshair paint.

getAnnotations

public java.util.List getAnnotations()
Returns the list of annotations.

Returns:
The list of annotations.

addAnnotation

public void addAnnotation(CategoryAnnotation annotation)
Adds an annotation to the plot.

Parameters:
annotation - the annotation.