|
Header
|
|||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Objectorg.jfree.chart.JFreeChart
public class JFreeChart
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
(which often includes the chart's legend), a Plot
and a
Dataset
(the plot in turn manages a
domain axis and a range axis).
You should use a ChartPanel
to display a chart in a GUI.
The ChartFactory
class contains static methods for creating
'ready-made' charts.
ChartPanel
,
ChartFactory
,
Title
,
Plot
,
Serialized FormField 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)
Creates a new chart based on the supplied plot. |
|
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. |
Method Summary | |
---|---|
void |
addChangeListener(ChartChangeListener listener)
Registers an object for notification of changes to the chart. |
void |
addLegend(LegendTitle legend)
Adds a legend to the plot and sends a ChartChangeEvent to all
registered listeners. |
void |
addProgressListener(ChartProgressListener listener)
Registers an object for notification of progress events relating to the chart. |
void |
addSubtitle(int index,
Title subtitle)
Adds a subtitle at a particular position in the subtitle list, and sends a ChartChangeEvent to all registered listeners. |
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). |
protected EntityCollection |
drawTitle(Title t,
java.awt.Graphics2D g2,
java.awt.geom.Rectangle2D area,
boolean entities)
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 . |
LegendTitle |
getLegend()
Returns the legend for the chart, if there is one. |
LegendTitle |
getLegend(int index)
Returns the nth legend for a chart, or null . |
org.jfree.ui.RectangleInsets |
getPadding()
Returns the padding between the chart border and the chart drawing area. |
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 for the chart. |
java.lang.Object |
getTextAntiAlias()
Returns the current value stored in the rendering hints table for RenderingHints.KEY_TEXT_ANTIALIASING . |
TextTitle |
getTitle()
Returns the main 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. |
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 |
removeLegend()
Removes the first legend in the chart and sends a ChartChangeEvent to all registered listeners. |
void |
removeProgressListener(ChartProgressListener listener)
Deregisters an object for notification of changes to the chart. |
void |
removeSubtitle(Title title)
Removes the specified subtitle and sends a ChartChangeEvent to
all registered listeners. |
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 |
setNotify(boolean notify)
Sets a flag that controls whether or not listeners receive ChartChangeEvent notifications. |
void |
setPadding(org.jfree.ui.RectangleInsets padding)
Sets the padding between the chart border and the chart drawing area, and sends a ChartChangeEvent to all registered listeners. |
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) and sends a ChartChangeEvent to all registered
listeners. |
void |
setTextAntiAlias(boolean flag)
Sets the value in the rendering hints table for RenderingHints.KEY_TEXT_ANTIALIASING to either
RenderingHints.VALUE_TEXT_ANTIALIAS_ON or
RenderingHints.VALUE_TEXT_ANTIALIAS_OFF , then sends a
ChartChangeEvent to all registered listeners. |
void |
setTextAntiAlias(java.lang.Object val)
Sets the value in the rendering hints table for RenderingHints.KEY_TEXT_ANTIALIASING and sends a
ChartChangeEvent to all registered listeners. |
void |
setTitle(java.lang.String text)
Sets the chart title and sends a ChartChangeEvent to all
registered listeners. |
void |
setTitle(TextTitle title)
Sets the main title for the chart and sends a ChartChangeEvent
to all registered listeners. |
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 |
---|
public static final org.jfree.ui.about.ProjectInfo INFO
public static final java.awt.Font DEFAULT_TITLE_FONT
public static final java.awt.Paint DEFAULT_BACKGROUND_PAINT
public static final java.awt.Image DEFAULT_BACKGROUND_IMAGE
public static final int DEFAULT_BACKGROUND_IMAGE_ALIGNMENT
public static final float DEFAULT_BACKGROUND_IMAGE_ALPHA
Constructor Detail |
---|
public JFreeChart(Plot plot)
ChartFactory
class 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.
plot
- the plot (null
not permitted).public JFreeChart(java.lang.String title, Plot plot)
DEFAULT_TITLE_FONT
) is used for the title, and the chart will
have a legend added automatically.
ChartFactory
class 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.
title
- the chart title (null
permitted).plot
- the plot (null
not permitted).public JFreeChart(java.lang.String title, java.awt.Font titleFont, Plot plot, boolean createLegend)
createLegend
argument specifies whether or not a legend
should be added to the chart.
ChartFactory
class 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.
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 |
---|
public java.awt.RenderingHints getRenderingHints()
null
).setRenderingHints(RenderingHints)
public void setRenderingHints(java.awt.RenderingHints renderingHints)
renderingHints
- the rendering hints (null
not
permitted).getRenderingHints()
public boolean isBorderVisible()
setBorderVisible(boolean)
public void setBorderVisible(boolean visible)
visible
- the flag.isBorderVisible()
public java.awt.Stroke getBorderStroke()
setBorderStroke(Stroke)
public void setBorderStroke(java.awt.Stroke stroke)
stroke
- the stroke.getBorderStroke()
public java.awt.Paint getBorderPaint()
setBorderPaint(Paint)
public void setBorderPaint(java.awt.Paint paint)
paint
- the paint.getBorderPaint()
public org.jfree.ui.RectangleInsets getPadding()
null
).setPadding(RectangleInsets)
public void setPadding(org.jfree.ui.RectangleInsets padding)
ChartChangeEvent
to all registered listeners.
padding
- the padding (null
not permitted).getPadding()
public TextTitle getTitle()
addSubtitle(Title)
method.
null
).setTitle(TextTitle)
public void setTitle(TextTitle title)
ChartChangeEvent
to all registered listeners. If you do not want a title for the
chart, set it to null
. If you want more than one title on
a chart, use the addSubtitle(Title)
method.
title
- the title (null
permitted).getTitle()
public void setTitle(java.lang.String text)
ChartChangeEvent
to all
registered listeners. This is a convenience method that ends up calling
the setTitle(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. If text
is null
the chart
title is set to null
.
text
- the title text (null
permitted).getTitle()
public void addLegend(LegendTitle legend)
ChartChangeEvent
to all
registered listeners.
legend
- the legend (null
not permitted).removeLegend()
public LegendTitle getLegend()
null
).getLegend(int)
public LegendTitle getLegend(int index)
null
.
index
- the legend index (zero-based).
null
).addLegend(LegendTitle)
public void removeLegend()
ChartChangeEvent
to all registered listeners.
getLegend()
public java.util.List getSubtitles()
null
).setSubtitles(List)
public void setSubtitles(java.util.List subtitles)
ChartChangeEvent
to all registered
listeners.
subtitles
- the new list of subtitles (null
not
permitted).getSubtitles()
public int getSubtitleCount()
getSubtitles()
public Title getSubtitle(int index)
index
- the index of the chart subtitle (zero based).
addSubtitle(Title)
public void addSubtitle(Title subtitle)
subtitle
- the subtitle (null
not permitted).getSubtitle(int)
public void addSubtitle(int index, Title subtitle)
ChartChangeEvent
to all registered listeners.
index
- the index (in the range 0 to getSubtitleCount()
).subtitle
- the subtitle to add (null
not permitted).public void clearSubtitles()
ChartChangeEvent
to all registered listeners.
addSubtitle(Title)
public void removeSubtitle(Title title)
ChartChangeEvent
to
all registered listeners.
title
- the title.addSubtitle(Title)
public Plot getPlot()
public CategoryPlot getCategoryPlot()
CategoryPlot
.
NOTE: if the plot is not an instance of CategoryPlot
, then a
ClassCastException
is thrown.
getPlot()
public XYPlot getXYPlot()
XYPlot
.
NOTE: if the plot is not an instance of XYPlot
, then a
ClassCastException
is thrown.
getPlot()
public boolean getAntiAlias()
setAntiAlias(boolean)
public void setAntiAlias(boolean flag)
Anti-aliasing usually improves the appearance of charts, but is slower.
flag
- the new value of the flag.getAntiAlias()
public java.lang.Object getTextAntiAlias()
RenderingHints.KEY_TEXT_ANTIALIASING
.
null
).setTextAntiAlias(Object)
public void setTextAntiAlias(boolean flag)
RenderingHints.KEY_TEXT_ANTIALIASING
to either
RenderingHints.VALUE_TEXT_ANTIALIAS_ON
or
RenderingHints.VALUE_TEXT_ANTIALIAS_OFF
, then sends a
ChartChangeEvent
to all registered listeners.
flag
- the new value of the flag.getTextAntiAlias()
,
setTextAntiAlias(Object)
public void setTextAntiAlias(java.lang.Object val)
RenderingHints.KEY_TEXT_ANTIALIASING
and sends a
ChartChangeEvent
to all registered listeners.
val
- the new value (null
permitted).getTextAntiAlias()
,
setTextAntiAlias(boolean)
public java.awt.Paint getBackgroundPaint()
null
).setBackgroundPaint(Paint)
public void setBackgroundPaint(java.awt.Paint paint)
ChartChangeEvent
to all registered listeners.
paint
- the paint (null
permitted).getBackgroundPaint()
public java.awt.Image getBackgroundImage()
null
if
there is no image.
null
).setBackgroundImage(Image)
public void setBackgroundImage(java.awt.Image image)
ChartChangeEvent
to all registered listeners.
image
- the image (null
permitted).getBackgroundImage()
public int getBackgroundImageAlignment()
org.jfree.ui.Align
class in the JCommon class
library.
setBackgroundImageAlignment(int)
public void setBackgroundImageAlignment(int alignment)
Align
class.
alignment
- the alignment.getBackgroundImageAlignment()
public float getBackgroundImageAlpha()
setBackgroundImageAlpha(float)
public void setBackgroundImageAlpha(float alpha)
alpha
- the alpha value.getBackgroundImageAlpha()
public boolean isNotify()
setNotify(boolean)
public void setNotify(boolean notify)
ChartChangeEvent
notifications.
notify
- a boolean.isNotify()
public void draw(java.awt.Graphics2D g2, java.awt.geom.Rectangle2D area)
This method is the focus of the entire JFreeChart library.
draw
in interface org.jfree.ui.Drawable
g2
- the graphics device.area
- the area within which the chart should be drawn.public void draw(java.awt.Graphics2D g2, java.awt.geom.Rectangle2D area, ChartRenderingInfo info)
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).public void draw(java.awt.Graphics2D g2, java.awt.geom.Rectangle2D chartArea, java.awt.geom.Point2D anchor, ChartRenderingInfo info)
This method is the focus of the entire JFreeChart library.
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).protected EntityCollection drawTitle(Title t, java.awt.Graphics2D g2, java.awt.geom.Rectangle2D area, boolean entities)
t
- the title (null
not permitted).g2
- the graphics device (null
not permitted).area
- the chart area, excluding any existing titles
(null
not permitted).entities
- a flag that controls whether or not an entity
collection is returned for the title.
null
).public java.awt.image.BufferedImage createBufferedImage(int width, int height)
width
- the width.height
- the height.
public java.awt.image.BufferedImage createBufferedImage(int width, int height, ChartRenderingInfo info)
width
- the width.height
- the height.info
- carries back chart state information (null
permitted).
public java.awt.image.BufferedImage createBufferedImage(int width, int height, int imageType, ChartRenderingInfo info)
width
- the width.height
- the height.imageType
- the image type.info
- carries back chart state information (null
permitted).
public java.awt.image.BufferedImage createBufferedImage(int imageWidth, int imageHeight, double drawWidth, double drawHeight, ChartRenderingInfo info)
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.
public void handleClick(int x, int y, ChartRenderingInfo info)
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.
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
(null
not permitted).public void addChangeListener(ChartChangeListener listener)
listener
- the listener (null
not permitted).removeChangeListener(ChartChangeListener)
public void removeChangeListener(ChartChangeListener listener)
listener
- the listener (null
not permitted)addChangeListener(ChartChangeListener)
public void fireChartChanged()
ChartChangeEvent
to all registered listeners.
This method is for convenience only.
protected void notifyListeners(ChartChangeEvent event)
ChartChangeEvent
to all registered listeners.
event
- information about the event that triggered the
notification.public void addProgressListener(ChartProgressListener listener)
listener
- the object being registered.removeProgressListener(ChartProgressListener)
public void removeProgressListener(ChartProgressListener listener)
listener
- the object being deregistered.addProgressListener(ChartProgressListener)
protected void notifyListeners(ChartProgressEvent event)
ChartProgressEvent
to all registered listeners.
event
- information about the event that triggered the
notification.public void titleChanged(TitleChangeEvent event)
titleChanged
in interface TitleChangeListener
event
- information about the chart title change.public void plotChanged(PlotChangeEvent event)
plotChanged
in interface PlotChangeListener
event
- information about the plot change.public boolean equals(java.lang.Object obj)
equals
in class java.lang.Object
obj
- the object (null
permitted).
public static void main(java.lang.String[] args)
args
- no arguments are honored.public java.lang.Object clone() throws java.lang.CloneNotSupportedException
clone
in class java.lang.Object
java.lang.CloneNotSupportedException
- if the chart is not cloneable.
|
Footer
|
|||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |