Class JFreeChart
- java.lang.Object
-
- org.jfree.chart.JFreeChart
-
- All Implemented Interfaces:
java.io.Serializable,java.lang.Cloneable,java.util.EventListener,PlotChangeListener,TitleChangeListener,Drawable
public class JFreeChart extends java.lang.Object implements Drawable, TitleChangeListener, 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
Titleobjects (which often includes the chart's legend), aPlotand aDataset(the plot in turn manages a domain axis and a range axis).You should use a
ChartPanelto display a chart in a GUI.The
ChartFactoryclass contains static methods for creating 'ready-made' charts.- See Also:
ChartPanel,ChartFactory,Title,Plot, Serialized Form
-
-
Field Summary
Fields Modifier and Type Field Description private java.awt.ImagebackgroundImageAn optional background image for the chart.private intbackgroundImageAlignmentThe alignment for the background image.private floatbackgroundImageAlphaThe alpha transparency for the background image.private java.awt.PaintbackgroundPaintPaint used to draw the background of the chart.private java.awt.PaintborderPaintThe paint used to draw the chart border (if visible).private java.awt.StrokeborderStrokeThe stroke used to draw the chart border (if visible).private booleanborderVisibleA flag that controls whether or not the chart border is drawn.private javax.swing.event.EventListenerListchangeListenersStorage for registered change listeners.static java.awt.ImageDEFAULT_BACKGROUND_IMAGEThe default background image.static intDEFAULT_BACKGROUND_IMAGE_ALIGNMENTThe default background image alignment.static floatDEFAULT_BACKGROUND_IMAGE_ALPHAThe default background image alpha.static java.awt.PaintDEFAULT_BACKGROUND_PAINTThe default background color.static java.awt.FontDEFAULT_TITLE_FONTThe default font for titles.private booleanelementHintingA flag that controls whether or not rendering hints that identify chart element should be added during rendering.private java.lang.StringidThe chart id (optional, will be used by JFreeSVG export).static java.awt.RenderingHints.KeyKEY_SUPPRESS_SHADOW_GENERATIONThe key for a rendering hint that can suppress the generation of a shadow effect when drawing the chart.private booleannotifyA flag that can be used to enable/disable notification of chart change events.private RectangleInsetspaddingThe padding between the chart border and the chart drawing area.private PlotplotDraws the visual representation of the data.private javax.swing.event.EventListenerListprogressListenersStorage for registered progress listeners.private java.awt.RenderingHintsrenderingHintsRendering hints that will be used for chart drawing.private static longserialVersionUIDFor serialization.private java.util.ListsubtitlesThe chart subtitles (zero, one or many).private TextTitletitleThe chart title (optional).
-
Constructor Summary
Constructors Constructor Description JFreeChart(java.lang.String title, java.awt.Font titleFont, Plot plot, boolean createLegend)Creates a new chart with the given title and plot.JFreeChart(java.lang.String title, Plot plot)Creates a new chart with the given title and plot.JFreeChart(Plot plot)Creates a new chart based on the supplied plot.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description voidaddChangeListener(ChartChangeListener listener)Registers an object for notification of changes to the chart.voidaddLegend(LegendTitle legend)Adds a legend to the plot and sends aChartChangeEventto all registered listeners.voidaddProgressListener(ChartProgressListener listener)Registers an object for notification of progress events relating to the chart.voidaddSubtitle(int index, Title subtitle)Adds a subtitle at a particular position in the subtitle list, and sends aChartChangeEventto all registered listeners.voidaddSubtitle(Title subtitle)Adds a chart subtitle, and notifies registered listeners that the chart has been modified.voidclearSubtitles()Clears all subtitles from the chart and sends aChartChangeEventto all registered listeners.java.lang.Objectclone()Clones the object, and takes care of listeners.private java.awt.geom.Rectangle2DcreateAlignedRectangle2D(Size2D dimensions, java.awt.geom.Rectangle2D frame, HorizontalAlignment hAlign, VerticalAlignment vAlign)Creates a rectangle that is aligned to the frame.java.awt.image.BufferedImagecreateBufferedImage(int width, int height)Creates and returns a buffered image into which the chart has been drawn.java.awt.image.BufferedImagecreateBufferedImage(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.BufferedImagecreateBufferedImage(int width, int height, int imageType, ChartRenderingInfo info)Creates and returns a buffered image into which the chart has been drawn.java.awt.image.BufferedImagecreateBufferedImage(int width, int height, ChartRenderingInfo info)Creates and returns a buffered image into which the chart has been drawn.voiddraw(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).voiddraw(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).voiddraw(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).protected EntityCollectiondrawTitle(Title t, java.awt.Graphics2D g2, java.awt.geom.Rectangle2D area, boolean entities)Draws a title.booleanequals(java.lang.Object obj)Tests this chart for equality with another object.voidfireChartChanged()Sends a defaultChartChangeEventto all registered listeners.booleangetAntiAlias()Returns a flag that indicates whether or not anti-aliasing is used when the chart is drawn.java.awt.ImagegetBackgroundImage()Returns the background image for the chart, ornullif there is no image.intgetBackgroundImageAlignment()Returns the background image alignment.floatgetBackgroundImageAlpha()Returns the alpha-transparency for the chart's background image.java.awt.PaintgetBackgroundPaint()Returns the paint used for the chart background.java.awt.PaintgetBorderPaint()Returns the paint used to draw the chart border (if visible).java.awt.StrokegetBorderStroke()Returns the stroke used to draw the chart border (if visible).CategoryPlotgetCategoryPlot()Returns the plot cast as aCategoryPlot.booleangetElementHinting()Returns the flag that controls whether or not rendering hints (ChartHints.KEY_BEGIN_ELEMENTandChartHints.KEY_END_ELEMENT) that identify chart elements are added during rendering.java.lang.StringgetID()Returns the ID for the chart.LegendTitlegetLegend()Returns the legend for the chart, if there is one.LegendTitlegetLegend(int index)Returns the nth legend for a chart, ornull.RectangleInsetsgetPadding()Returns the padding between the chart border and the chart drawing area.PlotgetPlot()Returns the plot for the chart.java.awt.RenderingHintsgetRenderingHints()Returns the collection of rendering hints for the chart.TitlegetSubtitle(int index)Returns a chart subtitle.intgetSubtitleCount()Returns the number of titles for the chart.java.util.ListgetSubtitles()Returns the list of subtitles for the chart.java.lang.ObjectgetTextAntiAlias()Returns the current value stored in the rendering hints table forRenderingHints.KEY_TEXT_ANTIALIASING.TextTitlegetTitle()Returns the main chart title.XYPlotgetXYPlot()Returns the plot cast as anXYPlot.voidhandleClick(int x, int y, ChartRenderingInfo info)Handles a 'click' on the chart.inthashCode()booleanisBorderVisible()Returns a flag that controls whether or not a border is drawn around the outside of the chart.booleanisNotify()Returns a flag that controls whether or not change events are sent to registered listeners.protected voidnotifyListeners(ChartChangeEvent event)Sends aChartChangeEventto all registered listeners.protected voidnotifyListeners(ChartProgressEvent event)Sends aChartProgressEventto all registered listeners.voidplotChanged(PlotChangeEvent event)Receives notification that the plot has changed, and passes this on to registered listeners.private voidreadObject(java.io.ObjectInputStream stream)Provides serialization support.voidremoveChangeListener(ChartChangeListener listener)Deregisters an object for notification of changes to the chart.voidremoveLegend()Removes the first legend in the chart and sends aChartChangeEventto all registered listeners.voidremoveProgressListener(ChartProgressListener listener)Deregisters an object for notification of changes to the chart.voidremoveSubtitle(Title title)Removes the specified subtitle and sends aChartChangeEventto all registered listeners.voidsetAntiAlias(boolean flag)Sets a flag that indicates whether or not anti-aliasing is used when the chart is drawn.voidsetBackgroundImage(java.awt.Image image)Sets the background image for the chart and sends aChartChangeEventto all registered listeners.voidsetBackgroundImageAlignment(int alignment)Sets the background alignment.voidsetBackgroundImageAlpha(float alpha)Sets the alpha-transparency for the chart's background image.voidsetBackgroundPaint(java.awt.Paint paint)Sets the paint used to fill the chart background and sends aChartChangeEventto all registered listeners.voidsetBorderPaint(java.awt.Paint paint)Sets the paint used to draw the chart border (if visible).voidsetBorderStroke(java.awt.Stroke stroke)Sets the stroke used to draw the chart border (if visible).voidsetBorderVisible(boolean visible)Sets a flag that controls whether or not a border is drawn around the outside of the chart.voidsetElementHinting(boolean hinting)Sets the flag that controls whether or not rendering hints (ChartHints.KEY_BEGIN_ELEMENTandChartHints.KEY_END_ELEMENT) that identify chart elements are added during rendering.voidsetID(java.lang.String id)Sets the ID for the chart.voidsetNotify(boolean notify)Sets a flag that controls whether or not listeners receiveChartChangeEventnotifications.voidsetPadding(RectangleInsets padding)Sets the padding between the chart border and the chart drawing area, and sends aChartChangeEventto all registered listeners.voidsetRenderingHints(java.awt.RenderingHints renderingHints)Sets the rendering hints for the chart.voidsetSubtitles(java.util.List subtitles)Sets the title list for the chart (completely replaces any existing titles) and sends aChartChangeEventto all registered listeners.voidsetTextAntiAlias(boolean flag)Sets the value in the rendering hints table forRenderingHints.KEY_TEXT_ANTIALIASINGto eitherRenderingHints.VALUE_TEXT_ANTIALIAS_ONorRenderingHints.VALUE_TEXT_ANTIALIAS_OFF, then sends aChartChangeEventto all registered listeners.voidsetTextAntiAlias(java.lang.Object val)Sets the value in the rendering hints table forRenderingHints.KEY_TEXT_ANTIALIASINGand sends aChartChangeEventto all registered listeners.voidsetTitle(java.lang.String text)Sets the chart title and sends aChartChangeEventto all registered listeners.voidsetTitle(TextTitle title)Sets the main title for the chart and sends aChartChangeEventto all registered listeners.voidtitleChanged(TitleChangeEvent event)Receives notification that a chart title has changed, and passes this on to registered listeners.private voidwriteObject(java.io.ObjectOutputStream stream)Provides serialization support.
-
-
-
Field Detail
-
serialVersionUID
private static final long serialVersionUID
For serialization.- See Also:
- Constant Field Values
-
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 final float DEFAULT_BACKGROUND_IMAGE_ALPHA
The default background image alpha.- See Also:
- Constant Field Values
-
KEY_SUPPRESS_SHADOW_GENERATION
public static final java.awt.RenderingHints.Key KEY_SUPPRESS_SHADOW_GENERATION
The key for a rendering hint that can suppress the generation of a shadow effect when drawing the chart. The hint value must be a Boolean.
-
renderingHints
private transient java.awt.RenderingHints renderingHints
Rendering hints that will be used for chart drawing. This should never benull.
-
id
private java.lang.String id
The chart id (optional, will be used by JFreeSVG export).
-
borderVisible
private boolean borderVisible
A flag that controls whether or not the chart border is drawn.
-
borderStroke
private transient java.awt.Stroke borderStroke
The stroke used to draw the chart border (if visible).
-
borderPaint
private transient java.awt.Paint borderPaint
The paint used to draw the chart border (if visible).
-
padding
private RectangleInsets padding
The padding between the chart border and the chart drawing area.
-
title
private TextTitle title
The chart title (optional).
-
subtitles
private java.util.List subtitles
The chart subtitles (zero, one or many). This field should never benull.
-
plot
private Plot plot
Draws the visual representation of the data.
-
backgroundPaint
private transient java.awt.Paint backgroundPaint
Paint used to draw the background of the chart.
-
backgroundImage
private transient java.awt.Image backgroundImage
An optional background image for the chart.
-
backgroundImageAlignment
private int backgroundImageAlignment
The alignment for the background image.
-
backgroundImageAlpha
private float backgroundImageAlpha
The alpha transparency for the background image.
-
changeListeners
private transient javax.swing.event.EventListenerList changeListeners
Storage for registered change listeners.
-
progressListeners
private transient javax.swing.event.EventListenerList progressListeners
Storage for registered progress listeners.
-
notify
private boolean notify
A flag that can be used to enable/disable notification of chart change events.
-
elementHinting
private boolean elementHinting
A flag that controls whether or not rendering hints that identify chart element should be added during rendering. This defaults to false and it should only be enabled if the output target will use the hints. JFreeSVG is one output target that supports these hints.
-
-
Constructor Detail
-
JFreeChart
public JFreeChart(Plot plot)
Creates a new chart based on the supplied plot. The chart will have a legend added automatically, but no title (although you can easily add one later).
Note that theChartFactoryclass contains a range of static methods that will return ready-made charts, and often this is a more convenient way to create charts than using this constructor.- Parameters:
plot- the plot (nullnot permitted).
-
JFreeChart
public JFreeChart(java.lang.String title, Plot plot)Creates a new chart with the given title and plot. A default font (DEFAULT_TITLE_FONT) is used for the title, and the chart will have a legend added automatically.
Note that theChartFactoryclass contains a range of static methods that will return ready-made charts, and often this is a more convenient way to create charts than using this constructor.- Parameters:
title- the chart title (nullpermitted).plot- the plot (nullnot permitted).
-
JFreeChart
public JFreeChart(java.lang.String title, java.awt.Font titleFont, Plot plot, boolean createLegend)Creates a new chart with the given title and plot. ThecreateLegendargument specifies whether or not a legend should be added to the chart.
Note that theChartFactoryclass contains a range of static methods that will return ready-made charts, and often this is a more convenient way to create charts than using this constructor.- Parameters:
title- the chart title (nullpermitted).titleFont- the font for displaying the chart title (nullpermitted).plot- controller of the visual representation of the data (nullnot permitted).createLegend- a flag indicating whether or not a legend should be created for the chart.
-
-
Method Detail
-
getID
public java.lang.String getID()
Returns the ID for the chart.- Returns:
- The ID for the chart (possibly
null).
-
setID
public void setID(java.lang.String id)
Sets the ID for the chart.- Parameters:
id- the id (nullpermitted).
-
getElementHinting
public boolean getElementHinting()
Returns the flag that controls whether or not rendering hints (ChartHints.KEY_BEGIN_ELEMENTandChartHints.KEY_END_ELEMENT) that identify chart elements are added during rendering. The default value isfalse.- Returns:
- A boolean.
- See Also:
setElementHinting(boolean)
-
setElementHinting
public void setElementHinting(boolean hinting)
Sets the flag that controls whether or not rendering hints (ChartHints.KEY_BEGIN_ELEMENTandChartHints.KEY_END_ELEMENT) that identify chart elements are added during rendering.- Parameters:
hinting- the new flag value.- See Also:
getElementHinting()
-
getRenderingHints
public java.awt.RenderingHints getRenderingHints()
Returns the collection of rendering hints for the chart.- Returns:
- The rendering hints for the chart (never
null). - See Also:
setRenderingHints(RenderingHints)
-
setRenderingHints
public void setRenderingHints(java.awt.RenderingHints renderingHints)
Sets the rendering hints for the chart. These will be added (using theGraphics2D.addRenderingHints()method) near the start of theJFreeChart.draw()method.- Parameters:
renderingHints- the rendering hints (nullnot permitted).- See Also:
getRenderingHints()
-
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.
- See Also:
setBorderVisible(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.- See Also:
isBorderVisible()
-
getBorderStroke
public java.awt.Stroke getBorderStroke()
Returns the stroke used to draw the chart border (if visible).- Returns:
- The border stroke.
- See Also:
setBorderStroke(Stroke)
-
setBorderStroke
public void setBorderStroke(java.awt.Stroke stroke)
Sets the stroke used to draw the chart border (if visible).- Parameters:
stroke- the stroke.- See Also:
getBorderStroke()
-
getBorderPaint
public java.awt.Paint getBorderPaint()
Returns the paint used to draw the chart border (if visible).- Returns:
- The border paint.
- See Also:
setBorderPaint(Paint)
-
setBorderPaint
public void setBorderPaint(java.awt.Paint paint)
Sets the paint used to draw the chart border (if visible).- Parameters:
paint- the paint.- See Also:
getBorderPaint()
-
getPadding
public RectangleInsets getPadding()
Returns the padding between the chart border and the chart drawing area.- Returns:
- The padding (never
null). - See Also:
setPadding(RectangleInsets)
-
setPadding
public void setPadding(RectangleInsets padding)
Sets the padding between the chart border and the chart drawing area, and sends aChartChangeEventto all registered listeners.- Parameters:
padding- the padding (nullnot permitted).- See Also:
getPadding()
-
getTitle
public TextTitle getTitle()
Returns the main chart title. Very often a chart will have just one title, so we make this case simple by providing accessor methods for the main title. However, multiple titles are supported - see theaddSubtitle(Title)method.- Returns:
- The chart title (possibly
null). - See Also:
setTitle(TextTitle)
-
setTitle
public void setTitle(TextTitle title)
Sets the main title for the chart and sends aChartChangeEventto all registered listeners. If you do not want a title for the chart, set it tonull. If you want more than one title on a chart, use theaddSubtitle(Title)method.- Parameters:
title- the title (nullpermitted).- See Also:
getTitle()
-
setTitle
public void setTitle(java.lang.String text)
Sets the chart title and sends aChartChangeEventto all registered listeners. This is a convenience method that ends up calling thesetTitle(TextTitle)method. If there is an existing title, its text is updated, otherwise a new title using the default font is added to the chart. Iftextisnullthe chart title is set tonull.- Parameters:
text- the title text (nullpermitted).- See Also:
getTitle()
-
addLegend
public void addLegend(LegendTitle legend)
Adds a legend to the plot and sends aChartChangeEventto all registered listeners.- Parameters:
legend- the legend (nullnot permitted).- See Also:
removeLegend()
-
getLegend
public LegendTitle getLegend()
Returns the legend for the chart, if there is one. Note that a chart can have more than one legend - this method returns the first.- Returns:
- The legend (possibly
null). - See Also:
getLegend(int)
-
getLegend
public LegendTitle getLegend(int index)
Returns the nth legend for a chart, ornull.- Parameters:
index- the legend index (zero-based).- Returns:
- The legend (possibly
null). - See Also:
addLegend(LegendTitle)
-
removeLegend
public void removeLegend()
Removes the first legend in the chart and sends aChartChangeEventto all registered listeners.- See Also:
getLegend()
-
getSubtitles
public java.util.List getSubtitles()
Returns the list of subtitles for the chart.- Returns:
- The subtitle list (possibly empty, but never
null). - See Also:
setSubtitles(List)
-
setSubtitles
public void setSubtitles(java.util.List subtitles)
Sets the title list for the chart (completely replaces any existing titles) and sends aChartChangeEventto all registered listeners.- Parameters:
subtitles- the new list of subtitles (nullnot permitted).- See Also:
getSubtitles()
-
getSubtitleCount
public int getSubtitleCount()
Returns the number of titles for the chart.- Returns:
- The number of titles for the chart.
- See Also:
getSubtitles()
-
getSubtitle
public Title getSubtitle(int index)
Returns a chart subtitle.- Parameters:
index- the index of the chart subtitle (zero based).- Returns:
- A chart subtitle.
- See Also:
addSubtitle(Title)
-
addSubtitle
public void addSubtitle(Title subtitle)
Adds a chart subtitle, and notifies registered listeners that the chart has been modified.- Parameters:
subtitle- the subtitle (nullnot permitted).- See Also:
getSubtitle(int)
-
addSubtitle
public void addSubtitle(int index, Title subtitle)Adds a subtitle at a particular position in the subtitle list, and sends aChartChangeEventto all registered listeners.- Parameters:
index- the index (in the range 0 togetSubtitleCount()).subtitle- the subtitle to add (nullnot permitted).
-
clearSubtitles
public void clearSubtitles()
Clears all subtitles from the chart and sends aChartChangeEventto all registered listeners.- See Also:
addSubtitle(Title)
-
removeSubtitle
public void removeSubtitle(Title title)
Removes the specified subtitle and sends aChartChangeEventto all registered listeners.- Parameters:
title- the title.- See Also:
addSubtitle(Title)
-
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 aCategoryPlot.NOTE: if the plot is not an instance of
CategoryPlot, then aClassCastExceptionis thrown.- Returns:
- The plot.
- See Also:
getPlot()
-
getXYPlot
public XYPlot getXYPlot()
Returns the plot cast as anXYPlot.NOTE: if the plot is not an instance of
XYPlot, then aClassCastExceptionis thrown.- Returns:
- The plot.
- See Also:
getPlot()
-
getAntiAlias
public boolean getAntiAlias()
Returns a flag that indicates whether or not anti-aliasing is used when the chart is drawn.- Returns:
- The flag.
- See Also:
setAntiAlias(boolean)
-
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.- See Also:
getAntiAlias()
-
getTextAntiAlias
public java.lang.Object getTextAntiAlias()
Returns the current value stored in the rendering hints table forRenderingHints.KEY_TEXT_ANTIALIASING.- Returns:
- The hint value (possibly
null). - See Also:
setTextAntiAlias(Object)
-
setTextAntiAlias
public void setTextAntiAlias(boolean flag)
Sets the value in the rendering hints table forRenderingHints.KEY_TEXT_ANTIALIASINGto eitherRenderingHints.VALUE_TEXT_ANTIALIAS_ONorRenderingHints.VALUE_TEXT_ANTIALIAS_OFF, then sends aChartChangeEventto all registered listeners.- Parameters:
flag- the new value of the flag.- See Also:
getTextAntiAlias(),setTextAntiAlias(Object)
-
setTextAntiAlias
public void setTextAntiAlias(java.lang.Object val)
Sets the value in the rendering hints table forRenderingHints.KEY_TEXT_ANTIALIASINGand sends aChartChangeEventto all registered listeners.- Parameters:
val- the new value (nullpermitted).- See Also:
getTextAntiAlias(),setTextAntiAlias(boolean)
-
getBackgroundPaint
public java.awt.Paint getBackgroundPaint()
Returns the paint used for the chart background.- Returns:
- The paint (possibly
null). - See Also:
setBackgroundPaint(Paint)
-
setBackgroundPaint
public void setBackgroundPaint(java.awt.Paint paint)
Sets the paint used to fill the chart background and sends aChartChangeEventto all registered listeners.- Parameters:
paint- the paint (nullpermitted).- See Also:
getBackgroundPaint()
-
getBackgroundImage
public java.awt.Image getBackgroundImage()
Returns the background image for the chart, ornullif there is no image.- Returns:
- The image (possibly
null). - See Also:
setBackgroundImage(Image)
-
setBackgroundImage
public void setBackgroundImage(java.awt.Image image)
Sets the background image for the chart and sends aChartChangeEventto all registered listeners.- Parameters:
image- the image (nullpermitted).- See Also:
getBackgroundImage()
-
getBackgroundImageAlignment
public int getBackgroundImageAlignment()
Returns the background image alignment. Alignment constants are defined in theAlignclass.- Returns:
- The alignment.
- See Also:
setBackgroundImageAlignment(int)
-
setBackgroundImageAlignment
public void setBackgroundImageAlignment(int alignment)
Sets the background alignment. Alignment options are defined by theAlignclass.- Parameters:
alignment- the alignment.- See Also:
getBackgroundImageAlignment()
-
getBackgroundImageAlpha
public float getBackgroundImageAlpha()
Returns the alpha-transparency for the chart's background image.- Returns:
- The alpha-transparency.
- See Also:
setBackgroundImageAlpha(float)
-
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.- See Also:
getBackgroundImageAlpha()
-
isNotify
public boolean isNotify()
Returns a flag that controls whether or not change events are sent to registered listeners.- Returns:
- A boolean.
- See Also:
setNotify(boolean)
-
setNotify
public void setNotify(boolean notify)
Sets a flag that controls whether or not listeners receiveChartChangeEventnotifications.- Parameters:
notify- a boolean.- See Also:
isNotify()
-
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.
-
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 (nullpermitted).info- records info about the drawing (null means collect no info).
-
createAlignedRectangle2D
private java.awt.geom.Rectangle2D createAlignedRectangle2D(Size2D dimensions, java.awt.geom.Rectangle2D frame, HorizontalAlignment hAlign, VerticalAlignment vAlign)
Creates a rectangle that is aligned to the frame.- Parameters:
dimensions- the dimensions for the rectangle.frame- the frame to align to.hAlign- the horizontal alignment.vAlign- the vertical alignment.- Returns:
- A rectangle.
-
drawTitle
protected EntityCollection drawTitle(Title t, java.awt.Graphics2D g2, java.awt.geom.Rectangle2D area, boolean entities)
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 (nullnot permitted).g2- the graphics device (nullnot permitted).area- the chart area, excluding any existing titles (nullnot permitted).entities- a flag that controls whether or not an entity collection is returned for the title.- Returns:
- An entity collection for the title (possibly
null).
-
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 (nullpermitted).- 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 (nullpermitted).- 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 (for example,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.- 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 (nullnot permitted).
-
addChangeListener
public void addChangeListener(ChartChangeListener listener)
Registers an object for notification of changes to the chart.- Parameters:
listener- the listener (nullnot permitted).- See Also:
removeChangeListener(ChartChangeListener)
-
removeChangeListener
public void removeChangeListener(ChartChangeListener listener)
Deregisters an object for notification of changes to the chart.- Parameters:
listener- the listener (nullnot permitted)- See Also:
addChangeListener(ChartChangeListener)
-
fireChartChanged
public void fireChartChanged()
Sends a defaultChartChangeEventto all registered listeners.This method is for convenience only.
-
notifyListeners
protected void notifyListeners(ChartChangeEvent event)
Sends aChartChangeEventto 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.- See Also:
removeProgressListener(ChartProgressListener)
-
removeProgressListener
public void removeProgressListener(ChartProgressListener listener)
Deregisters an object for notification of changes to the chart.- Parameters:
listener- the object being deregistered.- See Also:
addProgressListener(ChartProgressListener)
-
notifyListeners
protected void notifyListeners(ChartProgressEvent event)
Sends aChartProgressEventto 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:
titleChangedin interfaceTitleChangeListener- Parameters:
event- information about the chart title change.
-
plotChanged
public void plotChanged(PlotChangeEvent event)
Receives notification that the plot has changed, and passes this on to registered listeners.- Specified by:
plotChangedin interfacePlotChangeListener- Parameters:
event- information about the plot change.
-
equals
public boolean equals(java.lang.Object obj)
Tests this chart for equality with another object.- Overrides:
equalsin classjava.lang.Object- Parameters:
obj- the object (nullpermitted).- Returns:
- A boolean.
-
hashCode
public int hashCode()
- Overrides:
hashCodein classjava.lang.Object
-
writeObject
private void writeObject(java.io.ObjectOutputStream stream) throws java.io.IOExceptionProvides serialization support.- Parameters:
stream- the output stream.- Throws:
java.io.IOException- if there is an I/O error.
-
readObject
private void readObject(java.io.ObjectInputStream stream) throws java.io.IOException, java.lang.ClassNotFoundExceptionProvides serialization support.- Parameters:
stream- the input stream.- Throws:
java.io.IOException- if there is an I/O error.java.lang.ClassNotFoundException- if there is a classpath problem.
-
clone
public java.lang.Object clone() throws java.lang.CloneNotSupportedExceptionClones the object, and takes care of listeners. Note: caller shall register its own listeners on cloned graph.- Overrides:
clonein classjava.lang.Object- Returns:
- A clone.
- Throws:
java.lang.CloneNotSupportedException- if the chart is not cloneable.
-
-