Class Plot

java.lang.Object
org.jfree.chart.plot.Plot
All Implemented Interfaces:
Serializable, Cloneable, EventListener, AxisChangeListener, DatasetChangeListener
Direct Known Subclasses:
CategoryPlot, CompassPlot, ContourPlot, FastScatterPlot, MeterPlot, MultiplePiePlot, PiePlot, PolarPlot, ThermometerPlot, WaferMapPlot, XYPlot

public abstract class Plot
extends Object
implements AxisChangeListener, DatasetChangeListener, Serializable, Cloneable
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.
See Also:
Serialized Form
  • Field Details

    • ZERO

      public static final Number ZERO
      Useful constant representing zero.
    • DEFAULT_INSETS

      public static final Insets DEFAULT_INSETS
      The default insets.
    • DEFAULT_OUTLINE_STROKE

      public static final Stroke DEFAULT_OUTLINE_STROKE
      The default outline stroke.
    • DEFAULT_OUTLINE_PAINT

      public static final Paint DEFAULT_OUTLINE_PAINT
      The default outline color.
    • DEFAULT_FOREGROUND_ALPHA

      public static final float DEFAULT_FOREGROUND_ALPHA
      The default foreground alpha transparency.
      See Also:
      Constant Field Values
    • DEFAULT_BACKGROUND_ALPHA

      public static final float DEFAULT_BACKGROUND_ALPHA
      The default background alpha transparency.
      See Also:
      Constant Field Values
    • DEFAULT_BACKGROUND_PAINT

      public static final Paint DEFAULT_BACKGROUND_PAINT
      The default background color.
    • MINIMUM_WIDTH_TO_DRAW

      public static final int MINIMUM_WIDTH_TO_DRAW
      The minimum width at which the plot should be drawn.
      See Also:
      Constant Field Values
    • MINIMUM_HEIGHT_TO_DRAW

      public static final int MINIMUM_HEIGHT_TO_DRAW
      The minimum height at which the plot should be drawn.
      See Also:
      Constant Field Values
  • Method Details

    • getDatasetGroup

      public DatasetGroup getDatasetGroup()
      Returns the dataset group for the plot (not currently used).
      Returns:
      The dataset group.
    • getNoDataMessage

      public 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​(String message)
      Sets the message that is displayed when the dataset is empty or null.
      Parameters:
      message - the message (null permitted).
    • getNoDataMessageFont

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

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

      public Paint getNoDataMessagePaint()
      Returns the paint used to display the 'no data' message.
      Returns:
      the paint.
    • setNoDataMessagePaint

      public void setNoDataMessagePaint​(Paint paint)
      Sets the paint used to display the 'no data' message.
      Parameters:
      paint - the paint.
    • getPlotType

      public abstract 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.
    • 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​(Plot parent)
      Sets the parent plot.
      Parameters:
      parent - the parent plot.
    • getRootPlot

      public Plot getRootPlot()
      Returns the root plot.
      Returns:
      The root plot.
    • isSubplot

      public boolean isSubplot()
      Returns true if this plot is part of a combined plot structure.
      Returns:
      true if this plot is part of a combined plot structure.
    • getInsets

      public Insets getInsets()
      Returns the insets for the plot area.
      Returns:
      The insets.
    • setInsets

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

      public void setInsets​(Insets insets, boolean notify)
      Sets the insets for the plot and, if requested, notifies registered listeners that the plot has been modified.
      Parameters:
      insets - the new insets (null not permitted).
      notify - a flag that controls whether the registered listeners are notified.
    • getBackgroundPaint

      public Paint getBackgroundPaint()
      Returns the background color of the plot area.
      Returns:
      the paint (possibly null).
    • setBackgroundPaint

      public void setBackgroundPaint​(Paint paint)
      Sets the background color of the plot area and sends a PlotChangeEvent to all registered listeners.
      Parameters:
      paint - the paint (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.
    • getDrawingSupplier

      public DrawingSupplier getDrawingSupplier()
      Returns the drawing supplier for the plot.
      Returns:
      the drawing supplier (possibly null).
    • setDrawingSupplier

      public void setDrawingSupplier​(DrawingSupplier supplier)
      Sets the drawing supplier for the plot. The drawing supplier is responsible for supplying a limitless (possibly repeating) sequence of Paint, Stroke and Shape objects that the plot's renderer(s) can use to populate its(their) tables.
      Parameters:
      supplier - the new supplier.
    • getBackgroundImage

      public Image getBackgroundImage()
      Returns the background image that is used to fill the plot's background area.
      Returns:
      The image (possibly null).
    • setBackgroundImage

      public void setBackgroundImage​(Image image)
      Sets the background image for the plot.
      Parameters:
      image - the image (null permitted).
    • getBackgroundImageAlignment

      public int getBackgroundImageAlignment()
      Returns the background image alignment. Alignment constants are defined in the org.jfree.ui.Align class in the JCommon class library.
      Returns:
      The alignment.
    • setBackgroundImageAlignment

      public void setBackgroundImageAlignment​(int alignment)
      Sets the background alignment.

      Alignment options are defined by the Align class.

      Parameters:
      alignment - the alignment.
    • getOutlineStroke

      public Stroke getOutlineStroke()
      Returns the stroke used to outline the plot area.
      Returns:
      the stroke (possibly null).
    • setOutlineStroke

      public void setOutlineStroke​(Stroke stroke)
      Sets the stroke used to outline the plot area and sends a PlotChangeEvent to all registered listeners. If you set this attribute to null<.code>, no outline will be drawn. @param stroke the stroke (null permitted).
    • getOutlinePaint

      public Paint getOutlinePaint()
      Returns the color used to draw the outline of the plot area.
      Returns:
      The color (possibly null).
    • setOutlinePaint

      public void setOutlinePaint​(Paint paint)
      Sets the paint used to draw the outline of the plot area and sends a PlotChangeEvent to all registered listeners. If you set this attribute to null, no outline will be drawn.
      Parameters:
      paint - the 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.
    • getLegendItems

      public LegendItemCollection getLegendItems()
      Returns the legend items for the plot. By default, this method returns null. Subclasses should override to return a LegendItemCollection.
      Returns:
      The legend items for the plot (possibly null).
    • 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​(Graphics2D g2, Rectangle2D plotArea, PlotState parentState, PlotRenderingInfo 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.
      parentState - the state from the parent plot, if there is one.
      info - an object for collecting information about the drawing of the chart.
    • draw

      public void draw​(Graphics2D g2, Rectangle2D area, Point2D anchor, PlotState parentState, PlotRenderingInfo info)
      Implement later to make use of anchor.
      Parameters:
      g2 - the graphics device.
      area - the plot area.
      anchor - the anchor point.
      parentState - the parent state (if any).
      info - carries back plot rendering info.
    • drawBackground

      public void drawBackground​(Graphics2D g2, Rectangle2D area)
      Draws the plot background (the background color and/or image).

      This method will be called during the chart drawing process and is declared public so that it can be accessed by the renderers used by certain subclasses. You shouldn't need to call this method directly.

      Parameters:
      g2 - the graphics device.
      area - the area within which the plot should be drawn.
    • drawOutline

      public void drawOutline​(Graphics2D g2, Rectangle2D area)
      Draws the plot outline. This method will be called during the chart drawing process and is declared public so that it can be accessed by the renderers used by certain subclasses. You shouldn't need to call this method directly.
      Parameters:
      g2 - the graphics device.
      area - the area within which the plot should be drawn.
    • handleClick

      public void handleClick​(int x, int y, PlotRenderingInfo info)
      Handles a 'click' on the plot. Since the plot does not maintain any information about where it has been drawn, the plot rendering info is supplied as an argument.
      Parameters:
      x - the x coordinate (in Java2D space).
      y - the y coordinate (in Java2D space).
      info - an object containing information about the dimensions of the plot.
    • 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).
    • getDataAreaRatio

      public double getDataAreaRatio()
      Returns the data area ratio.
      Returns:
      The ratio.
    • setDataAreaRatio

      public void setDataAreaRatio​(double ratio)
      Sets the data area ratio.
      Parameters:
      ratio - the ratio.
    • equals

      public boolean equals​(Object obj)
      Tests this plot for equality with another object.
      Overrides:
      equals in class Object
      Parameters:
      obj - the object.
      Returns:
      true or false.
    • clone

      public Object clone() throws CloneNotSupportedException
      Creates a clone of the plot.
      Returns:
      A clone.
      Throws:
      CloneNotSupportedException - if some component of the plot does not support cloning.
    • resolveDomainAxisLocation

      public static org.jfree.ui.RectangleEdge resolveDomainAxisLocation​(AxisLocation location, PlotOrientation orientation)
      Resolves a domain axis location for a given plot orientation.
      Parameters:
      location - the location (null not permitted).
      orientation - the orientation (null not permitted).
      Returns:
      The edge (never null).
    • resolveRangeAxisLocation

      public static org.jfree.ui.RectangleEdge resolveRangeAxisLocation​(AxisLocation location, PlotOrientation orientation)
      Resolves a range axis location for a given plot orientation.
      Parameters:
      location - the location (null not permitted).
      orientation - the orientation (null not permitted).
      Returns:
      the edge (never null).
    • setPlotShowing

      public void setPlotShowing​(boolean showPlot)
    • isPlotShowing

      public boolean isPlotShowing()