Package org.jfree.chart.renderer.xy
Class XYDifferenceRenderer
java.lang.Object
org.jfree.chart.renderer.AbstractRenderer
org.jfree.chart.renderer.xy.AbstractXYItemRenderer
org.jfree.chart.renderer.xy.XYDifferenceRenderer
- All Implemented Interfaces:
Serializable
,Cloneable
,EventListener
,AnnotationChangeListener
,LegendItemSource
,XYItemRenderer
,PublicCloneable
public class XYDifferenceRenderer
extends AbstractXYItemRenderer
implements XYItemRenderer, PublicCloneable
A renderer for an

XYPlot
that highlights the differences between two
series. The example shown here is generated by the
DifferenceChartDemo1.java
program included in the JFreeChart
demo collection:

- See Also:
-
Field Summary
FieldsModifier and TypeFieldDescriptionprivate Shape
The shape to display in the legend item.private Paint
The paint used to highlight negative differences (y(0) invalid input: '<' y(1)).private Paint
The paint used to highlight positive differences (y(0) > y(1)).private boolean
This flag controls whether or not the x-coordinates (in Java2D space) are rounded to integers.private static final long
For serialization.private boolean
Display shapes at each point?Fields inherited from class org.jfree.chart.renderer.AbstractRenderer
DEFAULT_ITEM_LABEL_INSETS, DEFAULT_OUTLINE_PAINT, DEFAULT_OUTLINE_STROKE, DEFAULT_PAINT, DEFAULT_SHAPE, DEFAULT_STROKE, DEFAULT_VALUE_LABEL_FONT, DEFAULT_VALUE_LABEL_PAINT, ZERO
-
Constructor Summary
ConstructorsConstructorDescriptionCreates a new renderer with default attributes.XYDifferenceRenderer
(Paint positivePaint, Paint negativePaint, boolean shapes) Creates a new renderer. -
Method Summary
Modifier and TypeMethodDescriptionprivate boolean
areSeriesDisjoint
(XYDataset x_dataset) Determines if the two (2) series are disjoint.clone()
Returns a clone of the renderer.private void
createPolygon
(Graphics2D x_graphics, Rectangle2D x_dataArea, XYPlot x_plot, ValueAxis x_domainAxis, ValueAxis x_rangeAxis, boolean x_positive, LinkedList x_xValues, LinkedList x_yValues) Draws the visual representation of a polygonvoid
drawItem
(Graphics2D g2, XYItemRendererState state, Rectangle2D dataArea, PlotRenderingInfo info, XYPlot plot, ValueAxis domainAxis, ValueAxis rangeAxis, XYDataset dataset, int series, int item, CrosshairState crosshairState, int pass) Draws the visual representation of a single data item.protected void
drawItemPass0
(Graphics2D x_graphics, Rectangle2D x_dataArea, PlotRenderingInfo x_info, XYPlot x_plot, ValueAxis x_domainAxis, ValueAxis x_rangeAxis, XYDataset x_dataset, int x_series, int x_item, CrosshairState x_crosshairState) Draws the visual representation of a single data item, first pass.protected void
drawItemPass1
(Graphics2D x_graphics, Rectangle2D x_dataArea, PlotRenderingInfo x_info, XYPlot x_plot, ValueAxis x_domainAxis, ValueAxis x_rangeAxis, XYDataset x_dataset, int x_series, int x_item, CrosshairState x_crosshairState) Draws the visual representation of a single data item, second pass.boolean
Tests this renderer for equality with an arbitrary object.getLegendItem
(int datasetIndex, int series) Returns a default legend item for the specified series.Returns the shape used to represent a line in the legend.Returns the paint used to highlight negative differences.int
Returns2
, the number of passes required by the renderer.Returns the paint used to highlight positive differences.boolean
Returns the flag that controls whether or not the x-coordinates (in Java2D space) are rounded to integer values.boolean
Returns a flag that controls whether or not shapes are drawn for each data value.initialise
(Graphics2D g2, Rectangle2D dataArea, XYPlot plot, XYDataset data, PlotRenderingInfo info) Initialises the renderer and returns a state object that should be passed to subsequent calls to the drawItem() method.private boolean
isEitherSeriesDegenerate
(XYDataset x_dataset, boolean x_impliedZeroSubtrahend) Determines if a dataset is degenerate.private void
readObject
(ObjectInputStream stream) Provides serialization support.void
setLegendLine
(Shape line) Sets the shape used as a line in each legend item and sends aRendererChangeEvent
to all registered listeners.void
setNegativePaint
(Paint paint) Sets the paint used to highlight negative differences.void
setPositivePaint
(Paint paint) Sets the paint used to highlight positive differences and sends aRendererChangeEvent
to all registered listeners.void
setRoundXCoordinates
(boolean round) Sets the flag that controls whether or not the x-coordinates (in Java2D space) are rounded to integer values, and sends aRendererChangeEvent
to all registered listeners.void
setShapesVisible
(boolean flag) Sets a flag that controls whether or not shapes are drawn for each data value, and sends aRendererChangeEvent
to all registered listeners.private void
writeObject
(ObjectOutputStream stream) Provides serialization support.Methods inherited from class org.jfree.chart.renderer.xy.AbstractXYItemRenderer
addAnnotation, addAnnotation, addEntity, annotationChanged, beginElementGroup, calculateDomainMarkerTextAnchorPoint, drawAnnotations, drawDomainLine, drawDomainMarker, drawItemLabel, drawRangeLine, drawRangeMarker, fillDomainGridBand, fillRangeGridBand, findDomainBounds, findDomainBounds, findRangeBounds, findRangeBounds, getAnnotations, getDefaultItemLabelGenerator, getDefaultToolTipGenerator, getDrawingSupplier, getItemLabelGenerator, getLegendItemLabelGenerator, getLegendItems, getLegendItemToolTipGenerator, getLegendItemURLGenerator, getPlot, getSeriesItemLabelGenerator, getSeriesToolTipGenerator, getToolTipGenerator, getURLGenerator, hashCode, lineTo, moveTo, removeAnnotation, removeAnnotations, setDefaultItemLabelGenerator, setDefaultToolTipGenerator, setLegendItemLabelGenerator, setLegendItemToolTipGenerator, setLegendItemURLGenerator, setPlot, setSeriesItemLabelGenerator, setSeriesToolTipGenerator, setURLGenerator, updateCrosshairValues
Methods inherited from class org.jfree.chart.renderer.AbstractRenderer
addChangeListener, beginElementGroup, calculateLabelAnchorPoint, clearSeriesPaints, clearSeriesStrokes, endElementGroup, fireChangeEvent, getAutoPopulateSeriesFillPaint, getAutoPopulateSeriesOutlinePaint, getAutoPopulateSeriesOutlineStroke, getAutoPopulateSeriesPaint, getAutoPopulateSeriesShape, getAutoPopulateSeriesStroke, getDataBoundsIncludesVisibleSeriesOnly, getDefaultCreateEntities, getDefaultEntityRadius, getDefaultFillPaint, getDefaultItemLabelFont, getDefaultItemLabelPaint, getDefaultItemLabelsVisible, getDefaultLegendShape, getDefaultLegendTextFont, getDefaultLegendTextPaint, getDefaultNegativeItemLabelPosition, getDefaultOutlinePaint, getDefaultOutlineStroke, getDefaultPaint, getDefaultPositiveItemLabelPosition, getDefaultSeriesVisible, getDefaultSeriesVisibleInLegend, getDefaultShape, getDefaultStroke, getItemCreateEntity, getItemFillPaint, getItemLabelAnchorOffset, getItemLabelFont, getItemLabelInsets, getItemLabelPaint, getItemOutlinePaint, getItemOutlineStroke, getItemPaint, getItemShape, getItemStroke, getItemVisible, getLegendShape, getLegendTextFont, getLegendTextPaint, getNegativeItemLabelPosition, getPositiveItemLabelPosition, getSeriesCreateEntities, getSeriesFillPaint, getSeriesItemLabelFont, getSeriesItemLabelPaint, getSeriesNegativeItemLabelPosition, getSeriesOutlinePaint, getSeriesOutlineStroke, getSeriesPaint, getSeriesPositiveItemLabelPosition, getSeriesShape, getSeriesStroke, getSeriesVisible, getSeriesVisibleInLegend, getTreatLegendShapeAsLine, hasListener, isComputeItemLabelContrastColor, isItemLabelVisible, isSeriesItemLabelsVisible, isSeriesVisible, isSeriesVisibleInLegend, lookupLegendShape, lookupLegendTextFont, lookupLegendTextPaint, lookupSeriesFillPaint, lookupSeriesOutlinePaint, lookupSeriesOutlineStroke, lookupSeriesPaint, lookupSeriesShape, lookupSeriesStroke, notifyListeners, removeChangeListener, setAutoPopulateSeriesFillPaint, setAutoPopulateSeriesOutlinePaint, setAutoPopulateSeriesOutlineStroke, setAutoPopulateSeriesPaint, setAutoPopulateSeriesShape, setAutoPopulateSeriesStroke, setComputeItemLabelContrastColor, setDataBoundsIncludesVisibleSeriesOnly, setDefaultCreateEntities, setDefaultCreateEntities, setDefaultEntityRadius, setDefaultFillPaint, setDefaultFillPaint, setDefaultItemLabelFont, setDefaultItemLabelFont, setDefaultItemLabelPaint, setDefaultItemLabelPaint, setDefaultItemLabelsVisible, setDefaultItemLabelsVisible, setDefaultLegendShape, setDefaultLegendTextFont, setDefaultLegendTextPaint, setDefaultNegativeItemLabelPosition, setDefaultNegativeItemLabelPosition, setDefaultOutlinePaint, setDefaultOutlinePaint, setDefaultOutlineStroke, setDefaultOutlineStroke, setDefaultPaint, setDefaultPaint, setDefaultPositiveItemLabelPosition, setDefaultPositiveItemLabelPosition, setDefaultSeriesVisible, setDefaultSeriesVisible, setDefaultSeriesVisibleInLegend, setDefaultSeriesVisibleInLegend, setDefaultShape, setDefaultShape, setDefaultStroke, setDefaultStroke, setItemLabelAnchorOffset, setItemLabelInsets, setLegendShape, setLegendTextFont, setLegendTextPaint, setSeriesCreateEntities, setSeriesCreateEntities, setSeriesFillPaint, setSeriesFillPaint, setSeriesItemLabelFont, setSeriesItemLabelFont, setSeriesItemLabelPaint, setSeriesItemLabelPaint, setSeriesItemLabelsVisible, setSeriesItemLabelsVisible, setSeriesItemLabelsVisible, setSeriesNegativeItemLabelPosition, setSeriesNegativeItemLabelPosition, setSeriesOutlinePaint, setSeriesOutlinePaint, setSeriesOutlineStroke, setSeriesOutlineStroke, setSeriesPaint, setSeriesPaint, setSeriesPositiveItemLabelPosition, setSeriesPositiveItemLabelPosition, setSeriesShape, setSeriesShape, setSeriesStroke, setSeriesStroke, setSeriesVisible, setSeriesVisible, setSeriesVisibleInLegend, setSeriesVisibleInLegend, setTreatLegendShapeAsLine
Methods inherited from class java.lang.Object
finalize, getClass, notify, notifyAll, toString, wait, wait, wait
Methods inherited from interface org.jfree.chart.LegendItemSource
getLegendItems
Methods inherited from interface org.jfree.chart.renderer.xy.XYItemRenderer
addAnnotation, addAnnotation, addChangeListener, drawAnnotations, drawDomainLine, drawDomainMarker, drawRangeLine, drawRangeMarker, fillDomainGridBand, fillRangeGridBand, findDomainBounds, findRangeBounds, getDefaultCreateEntities, getDefaultFillPaint, getDefaultItemLabelFont, getDefaultItemLabelGenerator, getDefaultItemLabelPaint, getDefaultItemLabelsVisible, getDefaultNegativeItemLabelPosition, getDefaultOutlinePaint, getDefaultOutlineStroke, getDefaultPaint, getDefaultPositiveItemLabelPosition, getDefaultSeriesVisible, getDefaultSeriesVisibleInLegend, getDefaultShape, getDefaultStroke, getDefaultToolTipGenerator, getItemCreateEntity, getItemFillPaint, getItemLabelFont, getItemLabelGenerator, getItemLabelPaint, getItemOutlinePaint, getItemOutlineStroke, getItemPaint, getItemShape, getItemStroke, getItemVisible, getLegendItemLabelGenerator, getNegativeItemLabelPosition, getPlot, getPositiveItemLabelPosition, getSeriesCreateEntities, getSeriesFillPaint, getSeriesItemLabelFont, getSeriesItemLabelGenerator, getSeriesItemLabelPaint, getSeriesNegativeItemLabelPosition, getSeriesOutlinePaint, getSeriesOutlineStroke, getSeriesPaint, getSeriesPositiveItemLabelPosition, getSeriesShape, getSeriesStroke, getSeriesToolTipGenerator, getSeriesVisible, getSeriesVisibleInLegend, getToolTipGenerator, getURLGenerator, isItemLabelVisible, isSeriesItemLabelsVisible, isSeriesVisible, isSeriesVisibleInLegend, removeAnnotation, removeAnnotations, removeChangeListener, setDefaultCreateEntities, setDefaultCreateEntities, setDefaultFillPaint, setDefaultFillPaint, setDefaultItemLabelFont, setDefaultItemLabelGenerator, setDefaultItemLabelPaint, setDefaultItemLabelsVisible, setDefaultItemLabelsVisible, setDefaultNegativeItemLabelPosition, setDefaultNegativeItemLabelPosition, setDefaultOutlinePaint, setDefaultOutlinePaint, setDefaultOutlineStroke, setDefaultOutlineStroke, setDefaultPaint, setDefaultPaint, setDefaultPositiveItemLabelPosition, setDefaultPositiveItemLabelPosition, setDefaultSeriesVisible, setDefaultSeriesVisible, setDefaultSeriesVisibleInLegend, setDefaultSeriesVisibleInLegend, setDefaultShape, setDefaultShape, setDefaultStroke, setDefaultStroke, setDefaultToolTipGenerator, setLegendItemLabelGenerator, setPlot, setSeriesCreateEntities, setSeriesCreateEntities, setSeriesFillPaint, setSeriesFillPaint, setSeriesItemLabelFont, setSeriesItemLabelGenerator, setSeriesItemLabelPaint, setSeriesItemLabelsVisible, setSeriesItemLabelsVisible, setSeriesItemLabelsVisible, setSeriesNegativeItemLabelPosition, setSeriesNegativeItemLabelPosition, setSeriesOutlinePaint, setSeriesOutlinePaint, setSeriesOutlineStroke, setSeriesOutlineStroke, setSeriesPaint, setSeriesPaint, setSeriesPositiveItemLabelPosition, setSeriesPositiveItemLabelPosition, setSeriesShape, setSeriesShape, setSeriesStroke, setSeriesStroke, setSeriesToolTipGenerator, setSeriesVisible, setSeriesVisible, setSeriesVisibleInLegend, setSeriesVisibleInLegend, setURLGenerator
-
Field Details
-
serialVersionUID
private static final long serialVersionUIDFor serialization.- See Also:
-
positivePaint
The paint used to highlight positive differences (y(0) > y(1)). -
negativePaint
The paint used to highlight negative differences (y(0) invalid input: '<' y(1)). -
shapesVisible
private boolean shapesVisibleDisplay shapes at each point? -
legendLine
The shape to display in the legend item. -
roundXCoordinates
private boolean roundXCoordinatesThis flag controls whether or not the x-coordinates (in Java2D space) are rounded to integers. When set to true, this can avoid the vertical striping that anti-aliasing can generate. However, the rounding may not be appropriate for output in high resolution formats (for example, vector graphics formats such as SVG and PDF).
-
-
Constructor Details
-
XYDifferenceRenderer
public XYDifferenceRenderer()Creates a new renderer with default attributes. -
XYDifferenceRenderer
Creates a new renderer.- Parameters:
positivePaint
- the highlight color for positive differences (null
not permitted).negativePaint
- the highlight color for negative differences (null
not permitted).shapes
- draw shapes?
-
-
Method Details
-
getPositivePaint
Returns the paint used to highlight positive differences.- Returns:
- The paint (never
null
). - See Also:
-
setPositivePaint
Sets the paint used to highlight positive differences and sends aRendererChangeEvent
to all registered listeners.- Parameters:
paint
- the paint (null
not permitted).- See Also:
-
getNegativePaint
Returns the paint used to highlight negative differences.- Returns:
- The paint (never
null
). - See Also:
-
setNegativePaint
Sets the paint used to highlight negative differences.- Parameters:
paint
- the paint (null
not permitted).- See Also:
-
getShapesVisible
public boolean getShapesVisible()Returns a flag that controls whether or not shapes are drawn for each data value.- Returns:
- A boolean.
- See Also:
-
setShapesVisible
public void setShapesVisible(boolean flag) Sets a flag that controls whether or not shapes are drawn for each data value, and sends aRendererChangeEvent
to all registered listeners.- Parameters:
flag
- the flag.- See Also:
-
getLegendLine
Returns the shape used to represent a line in the legend.- Returns:
- The legend line (never
null
). - See Also:
-
setLegendLine
Sets the shape used as a line in each legend item and sends aRendererChangeEvent
to all registered listeners.- Parameters:
line
- the line (null
not permitted).- See Also:
-
getRoundXCoordinates
public boolean getRoundXCoordinates()Returns the flag that controls whether or not the x-coordinates (in Java2D space) are rounded to integer values.- Returns:
- The flag.
- See Also:
-
setRoundXCoordinates
public void setRoundXCoordinates(boolean round) Sets the flag that controls whether or not the x-coordinates (in Java2D space) are rounded to integer values, and sends aRendererChangeEvent
to all registered listeners.- Parameters:
round
- the new flag value.- See Also:
-
initialise
public XYItemRendererState initialise(Graphics2D g2, Rectangle2D dataArea, XYPlot plot, XYDataset data, PlotRenderingInfo info) Initialises the renderer and returns a state object that should be passed to subsequent calls to the drawItem() method. This method will be called before the first item is rendered, giving the renderer an opportunity to initialise any state information it wants to maintain. The renderer can do nothing if it chooses.- Specified by:
initialise
in interfaceXYItemRenderer
- Overrides:
initialise
in classAbstractXYItemRenderer
- Parameters:
g2
- the graphics device.dataArea
- the area inside the axes.plot
- the plot.data
- the data.info
- an optional info collection object to return data back to the caller.- Returns:
- A state object.
-
getPassCount
public int getPassCount()Returns2
, the number of passes required by the renderer. TheXYPlot
will run through the dataset this number of times.- Specified by:
getPassCount
in interfaceXYItemRenderer
- Overrides:
getPassCount
in classAbstractXYItemRenderer
- Returns:
- The number of passes required by the renderer.
-
drawItem
public void drawItem(Graphics2D g2, XYItemRendererState state, Rectangle2D dataArea, PlotRenderingInfo info, XYPlot plot, ValueAxis domainAxis, ValueAxis rangeAxis, XYDataset dataset, int series, int item, CrosshairState crosshairState, int pass) Draws the visual representation of a single data item.- Specified by:
drawItem
in interfaceXYItemRenderer
- Parameters:
g2
- the graphics device.state
- the renderer state.dataArea
- the area within which the data is being drawn.info
- collects information about the drawing.plot
- the plot (can be used to obtain standard color information etc).domainAxis
- the domain (horizontal) axis.rangeAxis
- the range (vertical) axis.dataset
- the dataset.series
- the series index (zero-based).item
- the item index (zero-based).crosshairState
- crosshair information for the plot (null
permitted).pass
- the pass index.
-
drawItemPass0
protected void drawItemPass0(Graphics2D x_graphics, Rectangle2D x_dataArea, PlotRenderingInfo x_info, XYPlot x_plot, ValueAxis x_domainAxis, ValueAxis x_rangeAxis, XYDataset x_dataset, int x_series, int x_item, CrosshairState x_crosshairState) Draws the visual representation of a single data item, first pass.- Parameters:
x_graphics
- the graphics device.x_dataArea
- the area within which the data is being drawn.x_info
- collects information about the drawing.x_plot
- the plot (can be used to obtain standard color information etc).x_domainAxis
- the domain (horizontal) axis.x_rangeAxis
- the range (vertical) axis.x_dataset
- the dataset.x_series
- the series index (zero-based).x_item
- the item index (zero-based).x_crosshairState
- crosshair information for the plot (null
permitted).
-
drawItemPass1
protected void drawItemPass1(Graphics2D x_graphics, Rectangle2D x_dataArea, PlotRenderingInfo x_info, XYPlot x_plot, ValueAxis x_domainAxis, ValueAxis x_rangeAxis, XYDataset x_dataset, int x_series, int x_item, CrosshairState x_crosshairState) Draws the visual representation of a single data item, second pass. In the second pass, the renderer draws the lines and shapes for the individual points in the two series.- Parameters:
x_graphics
- the graphics device.x_dataArea
- the area within which the data is being drawn.x_info
- collects information about the drawing.x_plot
- the plot (can be used to obtain standard color information etc).x_domainAxis
- the domain (horizontal) axis.x_rangeAxis
- the range (vertical) axis.x_dataset
- the dataset.x_series
- the series index (zero-based).x_item
- the item index (zero-based).x_crosshairState
- crosshair information for the plot (null
permitted).
-
isEitherSeriesDegenerate
Determines if a dataset is degenerate. A degenerate dataset is a dataset where either series has less than two (2) points.- Parameters:
x_dataset
- the dataset.x_impliedZeroSubtrahend
- if false, do not check the subtrahend- Returns:
- true if the dataset is degenerate.
-
areSeriesDisjoint
Determines if the two (2) series are disjoint. Disjoint series do not overlap in the domain space.- Parameters:
x_dataset
- the dataset.- Returns:
- true if the dataset is degenerate.
-
createPolygon
private void createPolygon(Graphics2D x_graphics, Rectangle2D x_dataArea, XYPlot x_plot, ValueAxis x_domainAxis, ValueAxis x_rangeAxis, boolean x_positive, LinkedList x_xValues, LinkedList x_yValues) Draws the visual representation of a polygon- Parameters:
x_graphics
- the graphics device.x_dataArea
- the area within which the data is being drawn.x_plot
- the plot (can be used to obtain standard color information etc).x_domainAxis
- the domain (horizontal) axis.x_rangeAxis
- the range (vertical) axis.x_positive
- indicates if the polygon is positive (true) or negative (false).x_xValues
- a linked list of the x values (expects values to be of type Double).x_yValues
- a linked list of the y values (expects values to be of type Double).
-
getLegendItem
Returns a default legend item for the specified series. Subclasses should override this method to generate customised items.- Specified by:
getLegendItem
in interfaceXYItemRenderer
- Overrides:
getLegendItem
in classAbstractXYItemRenderer
- Parameters:
datasetIndex
- the dataset index (zero-based).series
- the series index (zero-based).- Returns:
- A legend item for the series.
-
equals
Tests this renderer for equality with an arbitrary object.- Overrides:
equals
in classAbstractXYItemRenderer
- Parameters:
obj
- the object (null
permitted).- Returns:
- A boolean.
-
clone
Returns a clone of the renderer.- Specified by:
clone
in interfacePublicCloneable
- Overrides:
clone
in classAbstractXYItemRenderer
- Returns:
- A clone.
- Throws:
CloneNotSupportedException
- if the renderer cannot be cloned.
-
writeObject
Provides serialization support.- Parameters:
stream
- the output stream.- Throws:
IOException
- if there is an I/O error.
-
readObject
Provides serialization support.- Parameters:
stream
- the input stream.- Throws:
IOException
- if there is an I/O error.ClassNotFoundException
- if there is a classpath problem.
-