Package org.jfree.chart.renderer.xy
Class XYShapeRenderer
- java.lang.Object
-
- org.jfree.chart.renderer.AbstractRenderer
-
- org.jfree.chart.renderer.xy.AbstractXYItemRenderer
-
- org.jfree.chart.renderer.xy.XYShapeRenderer
-
- All Implemented Interfaces:
java.io.Serializable,java.lang.Cloneable,java.util.EventListener,AnnotationChangeListener,LegendItemSource,XYItemRenderer,PublicCloneable
public class XYShapeRenderer extends AbstractXYItemRenderer implements XYItemRenderer, java.lang.Cloneable, PublicCloneable, java.io.Serializable
A renderer that draws shapes at (x, y) coordinates and, if the dataset is an instance ofXYZDataset, fills the shapes with a paint that is based on the z-value (the paint is obtained from a lookup table). The renderer also allows for optional guidelines, horizontal and vertical lines connecting the shape to the edges of the plot.
The example shown here is generated by theXYShapeRendererDemo1.javaprogram included in the JFreeChart demo collection:
This renderer has similarities to, but also differences from, theXYLineAndShapeRenderer.- See Also:
- Serialized Form
-
-
Field Summary
Fields Modifier and Type Field Description private booleandrawOutlinesA flag that controls whether or not the shape outlines are drawn.private java.awt.PaintguideLinePaintThe paint used for drawing the guide lines (never null).private java.awt.StrokeguideLineStrokeThe stroke used for drawing the guide lines (never null).private booleanguideLinesVisibleFlag indicating if guide lines should be drawn for every item.private PaintScalepaintScaleThe paint scale (never null).private static longserialVersionUIDAuto generated serial version id.private booleanuseFillPaintA flag that controls whether or not the fill paint is used (if not, the fill paint is used).private booleanuseOutlinePaintA flag that controls whether or not the outline paint is used (if not, the regular paint is used).-
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
Constructors Constructor Description XYShapeRenderer()Creates a newXYShapeRendererinstance with default attributes.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description java.lang.Objectclone()Returns a clone of this renderer.voiddrawItem(java.awt.Graphics2D g2, XYItemRendererState state, java.awt.geom.Rectangle2D dataArea, PlotRenderingInfo info, XYPlot plot, ValueAxis domainAxis, ValueAxis rangeAxis, XYDataset dataset, int series, int item, CrosshairState crosshairState, int pass)Draws the block representing the specified item.booleanequals(java.lang.Object obj)Tests this instance for equality with an arbitrary object.RangefindDomainBounds(XYDataset dataset)Returns the lower and upper bounds (range) of the x-values in the specified dataset.RangefindRangeBounds(XYDataset dataset)Returns the range of values the renderer requires to display all the items from the specified dataset.RangefindZBounds(XYZDataset dataset)Return the range of z-values in the specified dataset.booleangetDrawOutlines()Returnstrueif outlines should be drawn for shapes, andfalseotherwise.java.awt.PaintgetGuideLinePaint()Returns the paint used to draw the guide lines.java.awt.StrokegetGuideLineStroke()Returns the stroke used to draw the guide lines.protected java.awt.PaintgetPaint(XYDataset dataset, int series, int item)Get the paint for a given series and item from a dataset.PaintScalegetPaintScale()Returns the paint scale used by the renderer.intgetPassCount()Returns the number of passes required by this renderer.booleangetUseFillPaint()Returnstrueif the renderer should use the fill paint setting to fill shapes, andfalseif it should just use the regular paint.booleangetUseOutlinePaint()Returns the flag that controls whether the outline paint is used for shape outlines.booleanisGuideLinesVisible()Returns a flag that controls whether or not guide lines are drawn for each data item (the lines are horizontal and vertical "crosshairs" linking the data point to the axes).private voidreadObject(java.io.ObjectInputStream stream)Provides serialization support.voidsetDrawOutlines(boolean flag)Sets the flag that controls whether outlines are drawn for shapes, and sends aRendererChangeEventto all registered listeners.voidsetGuideLinePaint(java.awt.Paint paint)Sets the paint used to draw the guide lines and sends aRendererChangeEventto all registered listeners.voidsetGuideLineStroke(java.awt.Stroke stroke)Sets the stroke used to draw the guide lines and sends aRendererChangeEventto all registered listeners.voidsetGuideLinesVisible(boolean visible)Sets the flag that controls whether or not guide lines are drawn for each data item and sends aRendererChangeEventto all registered listeners.voidsetPaintScale(PaintScale scale)Sets the paint scale used by the renderer and sends aRendererChangeEventto all registered listeners.voidsetUseFillPaint(boolean flag)Sets the flag that controls whether the fill paint is used to fill shapes, and sends aRendererChangeEventto all registered listeners.voidsetUseOutlinePaint(boolean use)Sets the flag that controls whether the outline paint is used for shape outlines, and sends aRendererChangeEventto all registered listeners.private voidwriteObject(java.io.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, findRangeBounds, getAnnotations, getDefaultItemLabelGenerator, getDefaultToolTipGenerator, getDrawingSupplier, getItemLabelGenerator, getLegendItem, getLegendItemLabelGenerator, getLegendItems, getLegendItemToolTipGenerator, getLegendItemURLGenerator, getPlot, getSeriesItemLabelGenerator, getSeriesToolTipGenerator, getToolTipGenerator, getURLGenerator, hashCode, initialise, 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, 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, getLegendItem, getLegendItemLabelGenerator, getNegativeItemLabelPosition, getPlot, getPositiveItemLabelPosition, getSeriesCreateEntities, getSeriesFillPaint, getSeriesItemLabelFont, getSeriesItemLabelGenerator, getSeriesItemLabelPaint, getSeriesNegativeItemLabelPosition, getSeriesOutlinePaint, getSeriesOutlineStroke, getSeriesPaint, getSeriesPositiveItemLabelPosition, getSeriesShape, getSeriesStroke, getSeriesToolTipGenerator, getSeriesVisible, getSeriesVisibleInLegend, getToolTipGenerator, getURLGenerator, initialise, 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 Detail
-
serialVersionUID
private static final long serialVersionUID
Auto generated serial version id.- See Also:
- Constant Field Values
-
paintScale
private PaintScale paintScale
The paint scale (never null).
-
drawOutlines
private boolean drawOutlines
A flag that controls whether or not the shape outlines are drawn.
-
useOutlinePaint
private boolean useOutlinePaint
A flag that controls whether or not the outline paint is used (if not, the regular paint is used).
-
useFillPaint
private boolean useFillPaint
A flag that controls whether or not the fill paint is used (if not, the fill paint is used).
-
guideLinesVisible
private boolean guideLinesVisible
Flag indicating if guide lines should be drawn for every item.
-
guideLinePaint
private transient java.awt.Paint guideLinePaint
The paint used for drawing the guide lines (never null).
-
guideLineStroke
private transient java.awt.Stroke guideLineStroke
The stroke used for drawing the guide lines (never null).
-
-
Method Detail
-
getPaintScale
public PaintScale getPaintScale()
Returns the paint scale used by the renderer.- Returns:
- The paint scale (never
null). - See Also:
setPaintScale(PaintScale)
-
setPaintScale
public void setPaintScale(PaintScale scale)
Sets the paint scale used by the renderer and sends aRendererChangeEventto all registered listeners.- Parameters:
scale- the scale (nullnot permitted).- See Also:
getPaintScale()
-
getDrawOutlines
public boolean getDrawOutlines()
Returnstrueif outlines should be drawn for shapes, andfalseotherwise.- Returns:
- A boolean.
- See Also:
setDrawOutlines(boolean)
-
setDrawOutlines
public void setDrawOutlines(boolean flag)
Sets the flag that controls whether outlines are drawn for shapes, and sends aRendererChangeEventto all registered listeners.In some cases, shapes look better if they do NOT have an outline, but this flag allows you to set your own preference.
- Parameters:
flag- the flag.- See Also:
getDrawOutlines()
-
getUseFillPaint
public boolean getUseFillPaint()
Returnstrueif the renderer should use the fill paint setting to fill shapes, andfalseif it should just use the regular paint.Refer to
XYLineAndShapeRendererDemo2.javato see the effect of this flag.- Returns:
- A boolean.
- See Also:
setUseFillPaint(boolean),getUseOutlinePaint()
-
setUseFillPaint
public void setUseFillPaint(boolean flag)
Sets the flag that controls whether the fill paint is used to fill shapes, and sends aRendererChangeEventto all registered listeners.- Parameters:
flag- the flag.- See Also:
getUseFillPaint()
-
getUseOutlinePaint
public boolean getUseOutlinePaint()
Returns the flag that controls whether the outline paint is used for shape outlines. If not, the regular series paint is used.- Returns:
- A boolean.
- See Also:
setUseOutlinePaint(boolean)
-
setUseOutlinePaint
public void setUseOutlinePaint(boolean use)
Sets the flag that controls whether the outline paint is used for shape outlines, and sends aRendererChangeEventto all registered listeners.- Parameters:
use- the flag.- See Also:
getUseOutlinePaint()
-
isGuideLinesVisible
public boolean isGuideLinesVisible()
Returns a flag that controls whether or not guide lines are drawn for each data item (the lines are horizontal and vertical "crosshairs" linking the data point to the axes).- Returns:
- A boolean.
- See Also:
setGuideLinesVisible(boolean)
-
setGuideLinesVisible
public void setGuideLinesVisible(boolean visible)
Sets the flag that controls whether or not guide lines are drawn for each data item and sends aRendererChangeEventto all registered listeners.- Parameters:
visible- the new flag value.- See Also:
isGuideLinesVisible()
-
getGuideLinePaint
public java.awt.Paint getGuideLinePaint()
Returns the paint used to draw the guide lines.- Returns:
- The paint (never
null). - See Also:
setGuideLinePaint(Paint)
-
setGuideLinePaint
public void setGuideLinePaint(java.awt.Paint paint)
Sets the paint used to draw the guide lines and sends aRendererChangeEventto all registered listeners.- Parameters:
paint- the paint (nullnot permitted).- See Also:
getGuideLinePaint()
-
getGuideLineStroke
public java.awt.Stroke getGuideLineStroke()
Returns the stroke used to draw the guide lines.- Returns:
- The stroke.
- See Also:
setGuideLineStroke(Stroke)
-
setGuideLineStroke
public void setGuideLineStroke(java.awt.Stroke stroke)
Sets the stroke used to draw the guide lines and sends aRendererChangeEventto all registered listeners.- Parameters:
stroke- the stroke (nullnot permitted).- See Also:
getGuideLineStroke()
-
findDomainBounds
public Range findDomainBounds(XYDataset dataset)
Returns the lower and upper bounds (range) of the x-values in the specified dataset.- Specified by:
findDomainBoundsin interfaceXYItemRenderer- Overrides:
findDomainBoundsin classAbstractXYItemRenderer- Parameters:
dataset- the dataset (nullpermitted).- Returns:
- The range (
nullif the dataset isnullor empty). - See Also:
AbstractXYItemRenderer.findRangeBounds(XYDataset)
-
findRangeBounds
public Range findRangeBounds(XYDataset dataset)
Returns the range of values the renderer requires to display all the items from the specified dataset.- Specified by:
findRangeBoundsin interfaceXYItemRenderer- Overrides:
findRangeBoundsin classAbstractXYItemRenderer- Parameters:
dataset- the dataset (nullpermitted).- Returns:
- The range (
nullif the dataset isnullor empty). - See Also:
AbstractXYItemRenderer.findDomainBounds(XYDataset)
-
findZBounds
public Range findZBounds(XYZDataset dataset)
Return the range of z-values in the specified dataset.- Parameters:
dataset- the dataset (nullpermitted).- Returns:
- The range (
nullif the dataset isnullor empty).
-
getPassCount
public int getPassCount()
Returns the number of passes required by this renderer.- Specified by:
getPassCountin interfaceXYItemRenderer- Overrides:
getPassCountin classAbstractXYItemRenderer- Returns:
2.
-
drawItem
public void drawItem(java.awt.Graphics2D g2, XYItemRendererState state, java.awt.geom.Rectangle2D dataArea, PlotRenderingInfo info, XYPlot plot, ValueAxis domainAxis, ValueAxis rangeAxis, XYDataset dataset, int series, int item, CrosshairState crosshairState, int pass)Draws the block representing the specified item.- Specified by:
drawItemin interfaceXYItemRenderer- Parameters:
g2- the graphics device.state- the state.dataArea- the data area.info- the plot rendering info.plot- the plot.domainAxis- the x-axis.rangeAxis- the y-axis.dataset- the dataset.series- the series index.item- the item index.crosshairState- the crosshair state.pass- the pass index.
-
getPaint
protected java.awt.Paint getPaint(XYDataset dataset, int series, int item)
Get the paint for a given series and item from a dataset.- Parameters:
dataset- the dataset.series- the series index.item- the item index.- Returns:
- The paint.
-
equals
public boolean equals(java.lang.Object obj)
Tests this instance for equality with an arbitrary object. This method returnstrueif and only if:objis an instance ofXYShapeRenderer(notnull);objhas the same field values as thisXYShapeRenderer;
- Overrides:
equalsin classAbstractXYItemRenderer- Parameters:
obj- the object (nullpermitted).- Returns:
- A boolean.
-
clone
public java.lang.Object clone() throws java.lang.CloneNotSupportedExceptionReturns a clone of this renderer.- Specified by:
clonein interfacePublicCloneable- Overrides:
clonein classAbstractXYItemRenderer- Returns:
- A clone of this renderer.
- Throws:
java.lang.CloneNotSupportedException- if there is a problem creating the clone.
-
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.
-
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.
-
-