## org.jfree.chart
Class JFreeChart

    java.lang.Object
      org.jfree.chart.JFreeChart

All Implemented Interfaces:
  java.io.Serializable, java.lang.Cloneable, java.util.EventListener, LegendChangeListener, PlotChangeListener, TitleChangeListener, org.jfree.ui.Drawable

    public class JFreeChart

extends java.lang.Object
implements org.jfree.ui.Drawable, TitleChangeListener, LegendChangeListener, PlotChangeListener, java.io.Serializable, java.lang.Cloneable

A chart class implemented using the Java 2D APIs. The current version supports bar charts, line charts, pie charts and xy plots (including time series data).

JFreeChart coordinates several objects to achieve its aim of being able to draw a chart on a Java 2D graphics device: a list of `Title` objects, a `Legend`, a `Plot` and a `Dataset` (the plot in turn manages a horizontal axis and a vertical axis).

You should use a `ChartPanel` to display a chart in a GUI.

The `ChartFactory` class contains static methods for creating 'ready-made' charts.

See Also:
  `ChartPanel`, `ChartFactory`, `Title`, `Legend`, `Plot`, Serialized Form

Field Summary
`static java.awt.Image` `DEFAULT_BACKGROUND_IMAGE` The default background image.
`static int` `DEFAULT_BACKGROUND_IMAGE_ALIGNMENT` The default background image alignment.
`static float` `DEFAULT_BACKGROUND_IMAGE_ALPHA` The default background image alpha.
`static java.awt.Paint` `DEFAULT_BACKGROUND_PAINT` The default background color.
`static java.awt.Font` `DEFAULT_TITLE_FONT` The default font for titles.
`static org.jfree.ui.about.ProjectInfo` `INFO` Information about the project.

Constructor Summary
`JFreeChart(Plot plot)` Constructs a chart.
`JFreeChart(java.lang.String title, java.awt.Font titleFont, Plot plot, boolean createLegend)` Constructs a chart.
`JFreeChart(java.lang.String title, Plot plot)` Creates a new chart.

Method Summary
`void` `addChangeListener(ChartChangeListener listener)` Registers an object for notification of changes to the chart.
`void` `addProgressListener(ChartProgressListener listener)` Registers an object for notification of progress events relating to the chart.
`void` `addSubtitle(Title subtitle)` Adds a chart subtitle, and notifies registered listeners that the chart has been modified.
`void` `clearSubtitles()` Clears all subtitles from the chart and sends a `ChartChangeEvent` to all registered listeners.
`java.lang.Object` `clone()` Clones the object, and takes care of listeners.
`java.awt.image.BufferedImage` `createBufferedImage(int width, int height)` Creates and returns a buffered image into which the chart has been drawn.
`java.awt.image.BufferedImage` `createBufferedImage(int width, int height, ChartRenderingInfo info)` Creates and returns a buffered image into which the chart has been drawn.
`java.awt.image.BufferedImage` `createBufferedImage(int imageWidth, int imageHeight, double drawWidth, double drawHeight, ChartRenderingInfo info)` Creates and returns a buffered image into which the chart has been drawn.
`java.awt.image.BufferedImage` `createBufferedImage(int width, int height, int imageType, ChartRenderingInfo info)` Creates and returns a buffered image into which the chart has been drawn.
`void` `draw(java.awt.Graphics2D g2, java.awt.geom.Rectangle2D area)` Draws the chart on a Java 2D graphics device (such as the screen or a printer).
`void` `draw(java.awt.Graphics2D g2, java.awt.geom.Rectangle2D area, ChartRenderingInfo info)` Draws the chart on a Java 2D graphics device (such as the screen or a printer).
`void` `draw(java.awt.Graphics2D g2, java.awt.geom.Rectangle2D chartArea, java.awt.geom.Point2D anchor, ChartRenderingInfo info)` Draws the chart on a Java 2D graphics device (such as the screen or a printer).
`void` `drawTitle(Title t, java.awt.Graphics2D g2, java.awt.geom.Rectangle2D area)` Draws a title.
`boolean` `equals(java.lang.Object obj)` Tests this chart for equality with another object.
`void` `fireChartChanged()` Sends a default `ChartChangeEvent` to all registered listeners.
`boolean` `getAntiAlias()` Returns a flag that indicates whether or not anti-aliasing is used when the chart is drawn.
`java.awt.Image` `getBackgroundImage()` Returns the background image for the chart, or `null` if there is no image.
`int` `getBackgroundImageAlignment()` Returns the background image alignment.
`float` `getBackgroundImageAlpha()` Returns the alpha-transparency for the chart's background image.
`java.awt.Paint` `getBackgroundPaint()` Returns the paint used for the chart background.
`java.awt.Paint` `getBorderPaint()` Returns the paint used to draw the chart border (if visible).
`java.awt.Stroke` `getBorderStroke()` Returns the stroke used to draw the chart border (if visible).
`CategoryPlot` `getCategoryPlot()` Returns the plot cast as a `CategoryPlot`.
`Legend` `getLegend()` Returns the chart legend.
`Plot` `getPlot()` Returns the plot for the chart.
`java.awt.RenderingHints` `getRenderingHints()` Returns the collection of rendering hints for the chart.
`Title` `getSubtitle(int index)` Returns a chart subtitle.
`int` `getSubtitleCount()` Returns the number of titles for the chart.
`java.util.List` `getSubtitles()` Returns the list of subtitles.
`TextTitle` `getTitle()` Returns the chart title.
`XYPlot` `getXYPlot()` Returns the plot cast as an `XYPlot`.
`void` `handleClick(int x, int y, ChartRenderingInfo info)` Handles a 'click' on the chart.
`boolean` `isBorderVisible()` Returns a flag that controls whether or not a border is drawn around the outside of the chart.
`boolean` `isNotify()` Returns a flag that controls whether or not change events are sent to registered listeners.
`void` `legendChanged(LegendChangeEvent event)` Receives notification that the chart legend has changed, and passes this on to registered listeners.
`static void` `main(java.lang.String[] args)` Prints information about JFreeChart to standard output.
`protected void` `notifyListeners(ChartChangeEvent event)` Sends a `ChartChangeEvent` to all registered listeners.
`protected void` `notifyListeners(ChartProgressEvent event)` Sends a `ChartProgressEvent` to all registered listeners.
`void` `plotChanged(PlotChangeEvent event)` Receives notification that the plot has changed, and passes this on to registered listeners.
`void` `removeChangeListener(ChartChangeListener listener)` Deregisters an object for notification of changes to the chart.
`void` `removeProgressListener(ChartProgressListener listener)` Deregisters an object for notification of changes to the chart.
`void` `setAntiAlias(boolean flag)` Sets a flag that indicates whether or not anti-aliasing is used when the chart is drawn.
`void` `setBackgroundImage(java.awt.Image image)` Sets the background image for the chart and sends a `ChartChangeEvent` to all registered listeners.
`void` `setBackgroundImageAlignment(int alignment)` Sets the background alignment.
`void` `setBackgroundImageAlpha(float alpha)` Sets the alpha-transparency for the chart's background image.
`void` `setBackgroundPaint(java.awt.Paint paint)` Sets the paint used to fill the chart background and sends a `ChartChangeEvent` to all registered listeners.
`void` `setBorderPaint(java.awt.Paint paint)` Sets the paint used to draw the chart border (if visible).
`void` `setBorderStroke(java.awt.Stroke stroke)` Sets the stroke used to draw the chart border (if visible).
`void` `setBorderVisible(boolean visible)` Sets a flag that controls whether or not a border is drawn around the outside of the chart.
`void` `setLegend(Legend legend)` Sets the chart legend.
`void` `setNotify(boolean notify)` Sets a flag that controls whether or not listeners receive `ChartChangeEvent` notifications.
`void` `setRenderingHints(java.awt.RenderingHints renderingHints)` Sets the rendering hints for the chart.
`void` `setSubtitles(java.util.List subtitles)` Sets the title list for the chart (completely replaces any existing titles).
`void` `setTitle(java.lang.String title)` Sets the chart title.
`void` `setTitle(TextTitle title)` Sets the title for the chart.
`void` `titleChanged(TitleChangeEvent event)` Receives notification that a chart title has changed, and passes this on to registered listeners.

Methods inherited from class java.lang.Object
`finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait`

Field Detail

### INFO

    public static final org.jfree.ui.about.ProjectInfo INFO

  Information about the project.

### DEFAULT_TITLE_FONT

    public static final java.awt.Font DEFAULT_TITLE_FONT

  The default font for titles.

### DEFAULT_BACKGROUND_PAINT

    public static final java.awt.Paint DEFAULT_BACKGROUND_PAINT

  The default background color.

### DEFAULT_BACKGROUND_IMAGE

    public static final java.awt.Image DEFAULT_BACKGROUND_IMAGE

  The default background image.

### DEFAULT_BACKGROUND_IMAGE_ALIGNMENT

    public static final int DEFAULT_BACKGROUND_IMAGE_ALIGNMENT

  The default background image alignment.

  See Also:
    Constant Field Values

### DEFAULT_BACKGROUND_IMAGE_ALPHA

    public static float DEFAULT_BACKGROUND_IMAGE_ALPHA

  The default background image alpha.

Constructor Detail

### JFreeChart

    public JFreeChart(Plot plot)

  Constructs a chart.

  Note that the `ChartFactory` class contains static methods that will return a ready-made chart.

  Parameters:
    `plot` - controller of the visual representation of the data (`null` not permitted).

### JFreeChart

    public JFreeChart(java.lang.String title,
                      Plot plot)

  Creates a new chart.

  Parameters:
    `title` - the chart title (`null` permitted).
    `plot` - the plot (`null` not permitted).

### JFreeChart

    public JFreeChart(java.lang.String title,
                      java.awt.Font titleFont,
                      Plot plot,
                      boolean createLegend)

  Constructs a chart.

  Note that the ChartFactory class contains static methods that will return a ready-made chart.

  Parameters:
    `title` - the chart title (`null` permitted).
    `titleFont` - the font for displaying the chart title (`null` permitted).
    `plot` - controller of the visual representation of the data (`null` not permitted).
    `createLegend` - a flag indicating whether or not a legend should be created for the chart.

Method Detail

### getRenderingHints

    public java.awt.RenderingHints getRenderingHints()

  Returns the collection of rendering hints for the chart.

  Returns:
    The rendering hints for the chart, never null.

### setRenderingHints

    public void setRenderingHints(java.awt.RenderingHints renderingHints)

  Sets the rendering hints for the chart. These will be added (using the Graphics2D.addRenderingHints() method) near the start of the JFreeChart.draw() method.

  Parameters:
    `renderingHints` - the rendering hints (`null` not permitted).

### isBorderVisible

    public boolean isBorderVisible()

  Returns a flag that controls whether or not a border is drawn around the outside of the chart.

  Returns:
    A boolean.

### setBorderVisible

    public void setBorderVisible(boolean visible)

  Sets a flag that controls whether or not a border is drawn around the outside of the chart.

  Parameters:
    `visible` - the flag.

### getBorderStroke

    public java.awt.Stroke getBorderStroke()

  Returns the stroke used to draw the chart border (if visible).

  Returns:
    The border stroke.

### setBorderStroke

    public void setBorderStroke(java.awt.Stroke stroke)

  Sets the stroke used to draw the chart border (if visible).

  Parameters:
    `stroke` - the stroke.

### getBorderPaint

    public java.awt.Paint getBorderPaint()

  Returns the paint used to draw the chart border (if visible).

  Returns:
    The border paint.

### setBorderPaint

    public void setBorderPaint(java.awt.Paint paint)

  Sets the paint used to draw the chart border (if visible).

  Parameters:
    `paint` - the paint.

### getTitle

    public TextTitle getTitle()

  Returns the chart title.

  Returns:
    The chart title (possibly `null`).

### setTitle

    public void setTitle(TextTitle title)

  Sets the title for the chart. If you do not want a title for the chart, set it to `null`.

  Parameters:
    `title` - the title (`null` permitted).

### setTitle

    public void setTitle(java.lang.String title)

  Sets the chart title. This is a convenience method that ends up calling the `setTitle(TextTitle)` method.

  Parameters:
    `title` - the new title (`null` permitted).

### getSubtitles

    public java.util.List getSubtitles()

  Returns the list of subtitles.

  Returns:
    the subtitle list.

### setSubtitles

    public void setSubtitles(java.util.List subtitles)

  Sets the title list for the chart (completely replaces any existing titles).

  Parameters:
    `subtitles` - the new list of subtitles.

### getSubtitleCount

    public int getSubtitleCount()

  Returns the number of titles for the chart.

  Returns:
    the number of titles for the chart.

### getSubtitle

    public Title getSubtitle(int index)

  Returns a chart subtitle.

  Parameters:
    `index` - the index of the chart subtitle (zero based).
  Returns:
    A chart subtitle.

### addSubtitle

    public void addSubtitle(Title subtitle)

  Adds a chart subtitle, and notifies registered listeners that the chart has been modified.

  Parameters:
    `subtitle` - the subtitle (`null` not permitted).

### clearSubtitles

    public void clearSubtitles()

  Clears all subtitles from the chart and sends a `ChartChangeEvent` to all registered listeners.

### getLegend

    public Legend getLegend()

  Returns the chart legend.

  Returns:
    the chart legend (possibly `null`).

### setLegend

    public void setLegend(Legend legend)

  Sets the chart legend. Registered listeners are notified that the chart has been modified. The legends chart reference is updated.

  Parameters:
    `legend` - the new chart legend (`null` permitted).

### getPlot

    public Plot getPlot()

  Returns the plot for the chart. The plot is a class responsible for coordinating the visual representation of the data, including the axes (if any).

  Returns:
    the plot.

### getCategoryPlot

    public CategoryPlot getCategoryPlot()

  Returns the plot cast as a `CategoryPlot`.

  NOTE: if the plot is not an instance of `CategoryPlot`, then a `ClassCastException` is thrown.

  Returns:
    the plot.

### getXYPlot

    public XYPlot getXYPlot()

  Returns the plot cast as an `XYPlot`.

  NOTE: if the plot is not an instance of `XYPlot`, then a `ClassCastException` is thrown.

  Returns:
    the plot.

### getAntiAlias

    public boolean getAntiAlias()

  Returns a flag that indicates whether or not anti-aliasing is used when the chart is drawn.

  Returns:
    the flag.

### setAntiAlias

    public void setAntiAlias(boolean flag)

  Sets a flag that indicates whether or not anti-aliasing is used when the chart is drawn.

  Anti-aliasing usually improves the appearance of charts, but is slower.

  Parameters:
    `flag` - the new value of the flag.

### getBackgroundPaint

    public java.awt.Paint getBackgroundPaint()

  Returns the paint used for the chart background.

  Returns:
    The paint (possibly `null`).

### setBackgroundPaint

    public void setBackgroundPaint(java.awt.Paint paint)

  Sets the paint used to fill the chart background and sends a `ChartChangeEvent` to all registered listeners.

  Parameters:
    `paint` - the paint (`null` permitted).

### getBackgroundImage

    public java.awt.Image getBackgroundImage()

  Returns the background image for the chart, or `null` if there is no image.

  Returns:
    The image (possibly `null`).

### setBackgroundImage

    public void setBackgroundImage(java.awt.Image image)

  Sets the background image for the chart and sends a `ChartChangeEvent` to all registered listeners.

  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.

### getBackgroundImageAlpha

    public float getBackgroundImageAlpha()

  Returns the alpha-transparency for the chart's background image.

  Returns:
    The alpha-transparency.

### setBackgroundImageAlpha

    public void setBackgroundImageAlpha(float alpha)

  Sets the alpha-transparency for the chart's background image. Registered listeners are notified that the chart has been changed.

  Parameters:
    `alpha` - the alpha value.

### isNotify

    public boolean isNotify()

  Returns a flag that controls whether or not change events are sent to registered listeners.

  Returns:
    A boolean.

### setNotify

    public void setNotify(boolean notify)

  Sets a flag that controls whether or not listeners receive `ChartChangeEvent` notifications.

  Parameters:
    `notify` - a boolean.

### draw

    public void draw(java.awt.Graphics2D g2,
                     java.awt.geom.Rectangle2D area)

  Draws the chart on a Java 2D graphics device (such as the screen or a printer).

  This method is the focus of the entire JFreeChart library.

  Specified by:
    `draw` in interface `org.jfree.ui.Drawable`
  Parameters:
    `g2` - the graphics device.
    `area` - the area within which the chart should be drawn.

### draw

    public void draw(java.awt.Graphics2D g2,
                     java.awt.geom.Rectangle2D area,
                     ChartRenderingInfo info)

  Draws the chart on a Java 2D graphics device (such as the screen or a printer). This method is the focus of the entire JFreeChart library.

  Parameters:
    `g2` - the graphics device.
    `area` - the area within which the chart should be drawn.
    `info` - records info about the drawing (null means collect no info).

### draw

    public void draw(java.awt.Graphics2D g2,
                     java.awt.geom.Rectangle2D chartArea,
                     java.awt.geom.Point2D anchor,
                     ChartRenderingInfo info)

  Draws the chart on a Java 2D graphics device (such as the screen or a printer).

  This method is the focus of the entire JFreeChart library.

  Parameters:
    `g2` - the graphics device.
    `chartArea` - the area within which the chart should be drawn.
    `anchor` - the anchor point (in Java2D space) for the chart (`null` permitted).
    `info` - records info about the drawing (null means collect no info).

### drawTitle

    public void drawTitle(Title t,
                          java.awt.Graphics2D g2,
                          java.awt.geom.Rectangle2D area)

  Draws a title. The title should be drawn at the top, bottom, left or right of the specified area, and the area should be updated to reflect the amount of space used by the title.

  Parameters:
    `t` - the title (`null` not permitted).
    `g2` - the graphics device (`null` not permitted).
    `area` - the chart area, excluding any existing titles (`null` not permitted).

### createBufferedImage

    public java.awt.image.BufferedImage createBufferedImage(int width,
                                                            int height)

  Creates and returns a buffered image into which the chart has been drawn.

  Parameters:
    `width` - the width.
    `height` - the height.
  Returns:
    a buffered image.

### createBufferedImage

    public java.awt.image.BufferedImage createBufferedImage(int width,
                                                            int height,
                                                            ChartRenderingInfo info)

  Creates and returns a buffered image into which the chart has been drawn.

  Parameters:
    `width` - the width.
    `height` - the height.
    `info` - carries back chart state information (`null` permitted).
  Returns:
    A buffered image.

### createBufferedImage

    public java.awt.image.BufferedImage createBufferedImage(int width,
                                                            int height,
                                                            int imageType,
                                                            ChartRenderingInfo info)

  Creates and returns a buffered image into which the chart has been drawn.

  Parameters:
    `width` - the width.
    `height` - the height.
    `imageType` - the image type.
    `info` - carries back chart state information (`null` permitted).
  Returns:
    a buffered image.

### createBufferedImage

    public java.awt.image.BufferedImage createBufferedImage(int imageWidth,
                                                            int imageHeight,
                                                            double drawWidth,
                                                            double drawHeight,
                                                            ChartRenderingInfo info)

  Creates and returns a buffered image into which the chart has been drawn.

  Parameters:
    `imageWidth` - the image width.
    `imageHeight` - the image height.
    `drawWidth` - the width for drawing the chart (will be scaled to fit image).
    `drawHeight` - the height for drawing the chart (will be scaled to fit image).
    `info` - optional object for collection chart dimension and entity information.
  Returns:
    a buffered image.

### handleClick

    public void handleClick(int x,
                            int y,
                            ChartRenderingInfo info)

  Handles a 'click' on the chart.

  JFreeChart is not a UI component, so some other object (e.g. ChartPanel) needs to capture the click event and pass it onto the JFreeChart object. If you are not using JFreeChart in a client application, then this method is not required (and hopefully it doesn't get in the way).

  Parameters:
    `x` - x-coordinate of the click (in Java2D space).
    `y` - y-coordinate of the click (in Java2D space).
    `info` - contains chart dimension and entity information.

### addChangeListener

    public void addChangeListener(ChartChangeListener listener)

  Registers an object for notification of changes to the chart.

  Parameters:
    `listener` - the listener (`null` not permitted).

### removeChangeListener

    public void removeChangeListener(ChartChangeListener listener)

  Deregisters an object for notification of changes to the chart.

  Parameters:
    `listener` - the listener (`null` not permitted)

### fireChartChanged

    public void fireChartChanged()

  Sends a default `ChartChangeEvent` to all registered listeners.

  This method is for convenience only.

### notifyListeners

    protected void notifyListeners(ChartChangeEvent event)

  Sends a `ChartChangeEvent` to all registered listeners.

  Parameters:
    `event` - information about the event that triggered the notification.

### addProgressListener

    public void addProgressListener(ChartProgressListener listener)

  Registers an object for notification of progress events relating to the chart.

  Parameters:
    `listener` - the object being registered.

### removeProgressListener

    public void removeProgressListener(ChartProgressListener listener)

  Deregisters an object for notification of changes to the chart.

  Parameters:
    `listener` - the object being deregistered.

### notifyListeners

    protected void notifyListeners(ChartProgressEvent event)

  Sends a `ChartProgressEvent` to all registered listeners.

  Parameters:
    `event` - information about the event that triggered the notification.

### titleChanged

    public void titleChanged(TitleChangeEvent event)

  Receives notification that a chart title has changed, and passes this on to registered listeners.

  Specified by:
    `titleChanged` in interface `TitleChangeListener`
  Parameters:
    `event` - information about the chart title change.

### legendChanged

    public void legendChanged(LegendChangeEvent event)

  Receives notification that the chart legend has changed, and passes this on to registered listeners.

  Specified by:
    `legendChanged` in interface `LegendChangeListener`
  Parameters:
    `event` - information about the chart legend change.

### plotChanged

    public void plotChanged(PlotChangeEvent event)

  Receives notification that the plot has changed, and passes this on to registered listeners.

  Specified by:
    `plotChanged` in interface `PlotChangeListener`
  Parameters:
    `event` - information about the plot change.

### equals

    public boolean equals(java.lang.Object obj)

  Tests this chart for equality with another object.

  Overrides:
    `equals` in class `java.lang.Object`
  Parameters:
    `obj` - the object (`null` permitted).
  Returns:
    A boolean.

### main

    public static void main(java.lang.String[] args)

  Prints information about JFreeChart to standard output.

  Parameters:
    `args` - no arguments are honored.

### clone

    public java.lang.Object clone()
                           throws java.lang.CloneNotSupportedException

  Clones the object, and takes care of listeners. Note: caller shall register its own listeners on cloned graph.

  Overrides:
    `clone` in class `java.lang.Object`
  Returns:
    A clone.
  Throws:
    `java.lang.CloneNotSupportedException` - if the chart is not cloneable.