com.jrefinery.chart
Class XYPlot

java.lang.Object
  extended by com.jrefinery.chart.Plot
      extended by com.jrefinery.chart.XYPlot
All Implemented Interfaces:
AxisConstants, com.jrefinery.chart.event.AxisChangeListener, HorizontalValuePlot, VerticalValuePlot, DatasetChangeListener, java.beans.PropertyChangeListener, java.util.EventListener
Direct Known Subclasses:
CombinedXYPlot, OverlaidXYPlot, PeriodMarkerPlot, SiamXYPlot

public class XYPlot
extends Plot
implements HorizontalValuePlot, VerticalValuePlot, java.beans.PropertyChangeListener

A general class for plotting data in the form of (x, y) pairs. XYPlot can use data from any class that implements the XYDataset interface (in the com.jrefinery.data package).

XYPlot makes use of a renderer to draw each point on the plot. By using different renderers, various chart types can be produced. The ChartFactory class contains static methods for creating pre-configured charts.

See Also:
ChartFactory, Plot, XYDataset

Field Summary
protected  ValueAxis domainAxis
          The domain axis (used for the x-values).
protected  java.util.List horizontalColors
          The colors for the horizontal lines.
protected  java.util.List horizontalLines
          A list of horizontal lines that will be overlaid on the plot.
protected  XYPlot parent
          The parent plot (used only when this plot is part of a combined plot).
protected  ValueAxis rangeAxis
          The range axis (used for the y-values).
protected  XYItemRenderer renderer
          Object responsible for drawing the visual representation of each point on the plot.
protected  java.util.List verticalColors
          The colors for the vertical lines.
protected  java.util.List verticalLines
          A list of (optional) vertical lines that will be overlaid on the plot.
protected  int weight
          The weight for this plot in a combined plot.
 
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
XYPlot(XYDataset data, ValueAxis domainAxis, ValueAxis rangeAxis)
          Constructs an XYPlot with the specified axes (other attributes take default values).
XYPlot(XYDataset data, ValueAxis domainAxis, ValueAxis rangeAxis, java.awt.Insets insets, java.awt.Paint backgroundPaint, java.awt.Image backgroundImage, float backgroundAlpha, java.awt.Stroke outlineStroke, java.awt.Paint outlinePaint, float alpha, XYItemRenderer renderer)
          Constructs a new XY plot.
XYPlot(XYDataset data, ValueAxis domainAxis, ValueAxis rangeAxis, XYItemRenderer renderer)
          Constructs an XYPlot with the specified axes and renderer (other attributes take default values).
 
Method Summary
 void addHorizontalLine(java.lang.Number value)
          Adds a horizontal line at the specified data value, using the default color red.
 void addHorizontalLine(java.lang.Number location, java.awt.Paint color)
          Adds a horizontal line at the specified data value, using the specified color.
 void addVerticalLine(java.lang.Number location)
          Adds a vertical line at location with default color blue.
 void addVerticalLine(java.lang.Number location, java.awt.Paint color)
          Adds a vertical of the given color at location with the given color.
 void datasetChanged(DatasetChangeEvent event)
          Receives notification of a change to the plot's dataset.
 void draw(boolean error, java.awt.Graphics2D g2, java.awt.geom.Rectangle2D plotArea, ChartRenderingInfo info)
           
protected  void draw(java.awt.Graphics2D g2, java.awt.geom.Rectangle2D plotArea, ChartRenderingInfo info)
          Draws the XY plot on a Java 2D graphics device (such as the screen or a printer).
 void draw(java.awt.Graphics2D g2, java.awt.geom.Rectangle2D plotArea, ChartRenderingInfo info, Dataset dataset)
           
protected  void drawHorizontalLine(java.awt.Graphics2D g2, java.awt.geom.Rectangle2D dataArea, double value, java.awt.Stroke stroke, java.awt.Paint paint)
          Utility method for drawing a crosshair on the chart (if required).
protected  void drawHorizontalLines(java.awt.Graphics2D g2, java.awt.geom.Rectangle2D dataArea)
          Support method for the draw(...) method.
protected  void drawVerticalLine(java.awt.Graphics2D g2, java.awt.geom.Rectangle2D dataArea, double value, java.awt.Stroke stroke, java.awt.Paint paint)
          Utility method for drawing a crosshair on the chart (if required).
protected  void drawVerticalLines(java.awt.Graphics2D g2, java.awt.geom.Rectangle2D dataArea)
          Support method for the draw(...) method.
 ValueAxis getDomainAxis()
          Returns the domain axis for the plot.
 HorizontalAxis getHorizontalAxis()
          Returns the horizontal axis.
 Range getHorizontalDataRange()
          Returns the range of data values to be plotted along the horizontal axis.
 ValueAxis getHorizontalValueAxis()
           
 XYItemRenderer getItemRenderer()
          Returns the item renderer.
 java.util.List getLegendItemLabels()
          Returns an array of labels to be displayed by the legend.
 Plot getParent()
          Returns the parent plot (or null if this plot is not part of a combined plot).
 java.lang.String getPlotType()
          Returns the plot type as a string.
 ValueAxis getRangeAxis()
          Returns the range axis for the plot.
 int getSeriesCount()
          Returns the number of series in the dataset for this plot.
 VerticalAxis getVerticalAxis()
          Returns the vertical axis.
 Range getVerticalDataRange()
          Returns the range for the data to be plotted against the vertical axis.
 ValueAxis getVerticalValueAxis()
           
 int getWeight()
          Returns the weight for this plot when it is used as a subplot within a combined plot.
 XYDataset getXYDataset()
          A convenience method that returns the dataset for the plot, cast as an XYDataset.
 void handleClick(int x, int y, ChartRenderingInfo info)
          Handles a 'click' on the plot by updating the anchor values...
 void handleClick(int x, int y, java.awt.geom.Rectangle2D plotArea)
           
 boolean isCompatibleDomainAxis(ValueAxis axis)
          Checks the compatibility of a domain axis, returning true if the axis is compatible with the plot, and false otherwise.
 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 isSubplot()
          Returns true if this plot is part of a combined plot structure, and false otherwise.
 void propertyChange(java.beans.PropertyChangeEvent event)
           
 void render(java.awt.Graphics2D g2, java.awt.geom.Rectangle2D dataArea, ChartRenderingInfo info, CrosshairInfo crosshairInfo)
          Draws a representation of the data within the dataArea region, using the current renderer.
 void setDomainAxis(ValueAxis axis)
          Sets the domain axis for the plot (this must be compatible with the plot type or an exception is thrown).
 void setParent(XYPlot parent)
          Sets the parent plot.
 void setRangeAxis(ValueAxis axis)
          Sets the range axis for the plot.
 void setWeight(int weight)
          Sets the weight for the plot.
 void setXYItemRenderer(XYItemRenderer renderer)
          Sets the item renderer, and notifies all listeners of a change to the plot.
 void zoom(double percent)
          Performs a zoom on the plot.
 
Methods inherited from class com.jrefinery.chart.Plot
addChangeListener, axisChanged, drawOutlineAndBackground, getBackgroundAlpha, getBackgroundPaint, getDataset, getFirstSeriesIndex, getForegroundAlpha, getInsets, getOutlinePaint, getOutlineStroke, getSeriesOutlinePaint, getSeriesOutlineStroke, getSeriesPaint, getSeriesStroke, getShape, getShape, getShapeFactory, 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

parent

protected XYPlot parent
The parent plot (used only when this plot is part of a combined plot).


weight

protected int weight
The weight for this plot in a combined plot.


domainAxis

protected ValueAxis domainAxis
The domain axis (used for the x-values).


rangeAxis

protected ValueAxis rangeAxis
The range axis (used for the y-values).


renderer

protected XYItemRenderer renderer
Object responsible for drawing the visual representation of each point on the plot.


verticalLines

protected java.util.List verticalLines
A list of (optional) vertical lines that will be overlaid on the plot.


verticalColors

protected java.util.List verticalColors
The colors for the vertical lines.


horizontalLines

protected java.util.List horizontalLines
A list of horizontal lines that will be overlaid on the plot.


horizontalColors

protected java.util.List horizontalColors
The colors for the horizontal lines.

Constructor Detail

XYPlot

public XYPlot(XYDataset data,
              ValueAxis domainAxis,
              ValueAxis rangeAxis)
Constructs an XYPlot with the specified axes (other attributes take default values).

Parameters:
domainAxis - The domain axis.
rangeAxis - The range axis.

XYPlot

public XYPlot(XYDataset data,
              ValueAxis domainAxis,
              ValueAxis rangeAxis,
              XYItemRenderer renderer)
Constructs an XYPlot with the specified axes and renderer (other attributes take default values).

Parameters:
domainAxis - The domain axis.
rangeAxis - The range axis.
renderer - The renderer

XYPlot

public XYPlot(XYDataset data,
              ValueAxis domainAxis,
              ValueAxis rangeAxis,
              java.awt.Insets insets,
              java.awt.Paint backgroundPaint,
              java.awt.Image backgroundImage,
              float backgroundAlpha,
              java.awt.Stroke outlineStroke,
              java.awt.Paint outlinePaint,
              float alpha,
              XYItemRenderer renderer)
Constructs a new XY plot.

Parameters:
domainAxis - The domain axis.
rangeAxis - The range axis.
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 the plot outline.
alpha - The alpha-transparency.
renderer - The renderer.
Method Detail

isSubplot

public boolean isSubplot()
Returns true if this plot is part of a combined plot structure, and false otherwise.

Overrides:
isSubplot in class Plot
Returns:
A flag indicating if this plot is a subplot.

getParent

public Plot getParent()
Returns the parent plot (or null if this plot is not part of a combined plot).

Returns:
The parent plot.

setParent

public void setParent(XYPlot parent)
Sets the parent plot.

Parameters:
parent - The parent plot.

getSeriesCount

public int getSeriesCount()
Returns the number of series in the dataset for this plot.

Returns:
The series count.

getLegendItemLabels

public java.util.List getLegendItemLabels()
Returns an array of labels to be displayed by the legend.

Specified by:
getLegendItemLabels in class Plot
Returns:
An array of legend item labels (or null).

getWeight

public int getWeight()
Returns the weight for this plot when it is used as a subplot within a combined plot.

Returns:
The weight.

setWeight

public void setWeight(int weight)
Sets the weight for the plot.

Parameters:
The - weight.

getItemRenderer

public XYItemRenderer getItemRenderer()
Returns the item renderer.

Returns:
The item renderer.

setXYItemRenderer

public void setXYItemRenderer(XYItemRenderer renderer)
Sets the item renderer, and notifies all listeners of a change to the plot.

Parameters:
renderer - The new renderer.

getXYDataset

public XYDataset getXYDataset()
A convenience method that returns the dataset for the plot, cast as an XYDataset.

Returns:
The dataset for the plot, cast as an XYDataset.

addVerticalLine

public void addVerticalLine(java.lang.Number location)
Adds a vertical line at location with default color blue.


addVerticalLine

public void addVerticalLine(java.lang.Number location,
                            java.awt.Paint color)
Adds a vertical of the given color at location with the given color.


addHorizontalLine

public void addHorizontalLine(java.lang.Number value)
Adds a horizontal line at the specified data value, using the default color red.

Parameters:
value - The data value.

addHorizontalLine

public void addHorizontalLine(java.lang.Number location,
                              java.awt.Paint color)
Adds a horizontal line at the specified data value, using the specified color.

Parameters:
value - The data value.
color - The line color.

getDomainAxis

public ValueAxis 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.

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.

isCompatibleDomainAxis

public boolean isCompatibleDomainAxis(ValueAxis 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, and false otherwise.

isCompatibleRangeAxis

public 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, and false otherwise.

draw

public void draw(java.awt.Graphics2D g2,
                 java.awt.geom.Rectangle2D plotArea,
                 ChartRenderingInfo info,
                 Dataset dataset)

draw

public void draw(boolean error,
                 java.awt.Graphics2D g2,
                 java.awt.geom.Rectangle2D plotArea,
                 ChartRenderingInfo info)

draw

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

XYPlot relies on an XYItemRenderer to draw each item in the plot. This allows the visual representation of the data to be changed easily.

The optional info argument collects information about the rendering of the plot (dimensions, tooltip information etc). Just pass in null if you do not need this information.

Specified by:
draw in class Plot
Parameters:
g2 - The graphics device.
plotArea - The area within which the plot (including axis labels) should be drawn.
info - Collects chart drawing information (null permitted).

render

public void render(java.awt.Graphics2D g2,
                   java.awt.geom.Rectangle2D dataArea,
                   ChartRenderingInfo info,
                   CrosshairInfo crosshairInfo)
Draws a representation of the data within the dataArea region, using the current renderer.

Parameters:
g2 - The graphics device.
dataArea - The region in which the data is to be drawn.
info - An optional object for collection dimension information.
crosshairInfo - An optional object for collecting crosshair info.

drawVerticalLine

protected void drawVerticalLine(java.awt.Graphics2D g2,
                                java.awt.geom.Rectangle2D dataArea,
                                double value,
                                java.awt.Stroke stroke,
                                java.awt.Paint paint)
Utility method for drawing a crosshair on the chart (if required).


drawHorizontalLine

protected void drawHorizontalLine(java.awt.Graphics2D g2,
                                  java.awt.geom.Rectangle2D dataArea,
                                  double value,
                                  java.awt.Stroke stroke,
                                  java.awt.Paint paint)
Utility method for drawing a crosshair on the chart (if required).


drawVerticalLines

protected void drawVerticalLines(java.awt.Graphics2D g2,
                                 java.awt.geom.Rectangle2D dataArea)
Support method for the draw(...) method.


drawHorizontalLines

protected void drawHorizontalLines(java.awt.Graphics2D g2,
                                   java.awt.geom.Rectangle2D dataArea)
Support method for the draw(...) method.


handleClick

public void handleClick(int x,
                        int y,
                        ChartRenderingInfo info)
Handles a 'click' on the plot by updating the anchor values...

Overrides:
handleClick in class Plot
Parameters:
x - The x coordinate.
y - The y coordinate.

handleClick

public void handleClick(int x,
                        int y,
                        java.awt.geom.Rectangle2D plotArea)

zoom

public void zoom(double percent)
Description copied from class: Plot
Performs a zoom on the plot. Subclasses will implement a behaviour that is appropriate to the type of plot.

Specified by:
zoom in class Plot

getPlotType

public java.lang.String getPlotType()
Returns the plot type as a string.

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

getHorizontalDataRange

public Range getHorizontalDataRange()
Description copied from interface: HorizontalValuePlot
Returns the range of data values to be plotted along the horizontal axis.

Specified by:
getHorizontalDataRange in interface HorizontalValuePlot
Returns:
The range.

getVerticalDataRange

public Range getVerticalDataRange()
Description copied from interface: VerticalValuePlot
Returns the range for the data to be plotted against the vertical axis.

Specified by:
getVerticalDataRange in interface VerticalValuePlot
Returns:
The range.

propertyChange

public void propertyChange(java.beans.PropertyChangeEvent event)
Specified by:
propertyChange in interface java.beans.PropertyChangeListener

datasetChanged

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

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

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

getHorizontalAxis

public HorizontalAxis getHorizontalAxis()
Returns the horizontal axis.

Returns:
The horizontal axis.

getHorizontalValueAxis

public ValueAxis getHorizontalValueAxis()
Specified by:
getHorizontalValueAxis in interface HorizontalValuePlot

getVerticalAxis

public VerticalAxis getVerticalAxis()
Returns the vertical axis.

Returns:
The vertical axis.

getVerticalValueAxis

public ValueAxis getVerticalValueAxis()
Specified by:
getVerticalValueAxis in interface VerticalValuePlot

setDomainAxis

public void setDomainAxis(ValueAxis 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

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 (null permitted).
Throws:
AxisNotCompatibleException


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.