java.lang.Object
org.jfree.chart.renderer.AbstractRenderer
org.jfree.chart.renderer.xy.AbstractXYItemRenderer
org.jfree.chart.renderer.xy.XYBarRenderer
- All Implemented Interfaces:
Serializable
,Cloneable
,EventListener
,AnnotationChangeListener
,LegendItemSource
,XYItemRenderer
,PublicCloneable
- Direct Known Subclasses:
ClusteredXYBarRenderer
,StackedXYBarRenderer
public class XYBarRenderer
extends AbstractXYItemRenderer
implements XYItemRenderer, Cloneable, PublicCloneable, Serializable
A renderer that draws bars on an
XYPlot
(requires an
IntervalXYDataset
). The example shown here is generated by the
XYBarChartDemo1.java
program included in the JFreeChart
demo collection:
- See Also:
-
Nested Class Summary
Modifier and TypeClassDescriptionprotected class
The state class used by this renderer. -
Field Summary
Fields inherited from class org.jfree.chart.renderer.AbstractRenderer
DEFAULT_OUTLINE_PAINT, DEFAULT_OUTLINE_STROKE, DEFAULT_PAINT, DEFAULT_SHAPE, DEFAULT_STROKE, DEFAULT_VALUE_LABEL_FONT, DEFAULT_VALUE_LABEL_PAINT, ZERO
-
Constructor Summary
ConstructorDescriptionThe default constructor.XYBarRenderer
(double margin) Constructs a new renderer. -
Method Summary
Modifier and TypeMethodDescriptionclone()
Returns a clone of the renderer.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.protected void
drawItemLabel
(Graphics2D g2, XYDataset dataset, int series, int item, XYPlot plot, XYItemLabelGenerator generator, Rectangle2D bar, boolean negative) Draws an item label.boolean
Tests this renderer for equality with an arbitrary object.findDomainBounds
(XYDataset dataset) Returns the lower and upper bounds (range) of the x-values in the specified dataset.findRangeBounds
(XYDataset dataset) Returns the lower and upper bounds (range) of the y-values in the specified dataset.double
Returns the bar alignment factor.Returns the bar painter.double
getBase()
Returns the base value for the bars.static XYBarPainter
Returns the default bar painter.static boolean
Returns the default value for theshadowsVisible
flag.Returns the gradient paint transformer (an object used to transform gradient paint objects to fit each bar).Returns the shape used to represent bars in each legend item.getLegendItem
(int datasetIndex, int series) Returns a default legend item for the specified series.double
Returns the margin which is a percentage amount by which the bars are trimmed.Returns the fallback position for negative item labels that don't fit within a bar.Returns the fallback position for positive item labels that don't fit within a bar.boolean
Returns the flag that controls whether or not shadows are drawn for the bars.double
Returns the shadow x-offset.double
Returns the shadow y-offset.boolean
Returns a flag that determines whether the y-interval from the dataset is used to calculate the length of each bar.initialise
(Graphics2D g2, Rectangle2D dataArea, XYPlot plot, XYDataset dataset, PlotRenderingInfo info) Initialises the renderer and returns a state object that should be passed to all subsequent calls to the drawItem() method.boolean
Returns a flag that controls whether or not bar outlines are drawn.void
setBarAlignmentFactor
(double factor) Sets the bar alignment factor and sends aRendererChangeEvent
to all registered listeners.void
setBarPainter
(XYBarPainter painter) Sets the bar painter and sends aRendererChangeEvent
to all registered listeners.void
setBase
(double base) Sets the base value for the bars and sends aRendererChangeEvent
to all registered listeners.static void
setDefaultBarPainter
(XYBarPainter painter) Sets the default bar painter.static void
setDefaultShadowsVisible
(boolean visible) Sets the default value for the shadows visible flag.void
setDrawBarOutline
(boolean draw) Sets the flag that controls whether or not bar outlines are drawn and sends aRendererChangeEvent
to all registered listeners.void
setGradientPaintTransformer
(GradientPaintTransformer transformer) Sets the gradient paint transformer and sends aRendererChangeEvent
to all registered listeners.void
setLegendBar
(Shape bar) Sets the shape used to represent bars in each legend item and sends aRendererChangeEvent
to all registered listeners.void
setMargin
(double margin) Sets the percentage amount by which the bars are trimmed and sends aRendererChangeEvent
to all registered listeners.void
Sets the fallback position for negative item labels that don't fit within a bar, and sends aRendererChangeEvent
to all registered listeners.void
Sets the fallback position for positive item labels that don't fit within a bar, and sends aRendererChangeEvent
to all registered listeners.void
setShadowVisible
(boolean visible) Sets the flag that controls whether or not the renderer draws shadows for the bars, and sends aRendererChangeEvent
to all registered listeners.void
setShadowXOffset
(double offset) Sets the x-offset for the bar shadow and sends aRendererChangeEvent
to all registered listeners.void
setShadowYOffset
(double offset) Sets the y-offset for the bar shadow and sends aRendererChangeEvent
to all registered listeners.void
setUseYInterval
(boolean use) Sets the flag that determines whether the y-interval from the dataset is used to calculate the length of each bar, and sends aRendererChangeEvent
to all registered listeners.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, getLegendItemLabelGenerator, getLegendItems, getLegendItemToolTipGenerator, getLegendItemURLGenerator, getPassCount, getPlot, getSeriesItemLabelGenerator, getSeriesToolTipGenerator, getToolTipGenerator, getURLGenerator, 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, 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, hashCode, hasListener, isItemLabelVisible, isSeriesItemLabelsVisible, isSeriesVisible, isSeriesVisibleInLegend, lookupLegendShape, lookupLegendTextFont, lookupLegendTextPaint, lookupSeriesFillPaint, lookupSeriesOutlinePaint, lookupSeriesOutlineStroke, lookupSeriesPaint, lookupSeriesShape, lookupSeriesStroke, notifyListeners, removeChangeListener, setAutoPopulateSeriesFillPaint, setAutoPopulateSeriesOutlinePaint, setAutoPopulateSeriesOutlineStroke, setAutoPopulateSeriesPaint, setAutoPopulateSeriesShape, setAutoPopulateSeriesStroke, 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, 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, getLegendItemLabelGenerator, getNegativeItemLabelPosition, getPassCount, 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
-
Constructor Details
-
XYBarRenderer
public XYBarRenderer()The default constructor. -
XYBarRenderer
public XYBarRenderer(double margin) Constructs a new renderer.- Parameters:
margin
- the percentage amount to trim from the width of each bar.
-
-
Method Details
-
getDefaultBarPainter
Returns the default bar painter.- Returns:
- The default bar painter.
-
setDefaultBarPainter
Sets the default bar painter.- Parameters:
painter
- the painter (null
not permitted).
-
getDefaultShadowsVisible
public static boolean getDefaultShadowsVisible()Returns the default value for theshadowsVisible
flag.- Returns:
- A boolean.
- See Also:
-
setDefaultShadowsVisible
public static void setDefaultShadowsVisible(boolean visible) Sets the default value for the shadows visible flag.- Parameters:
visible
- the new value for the default.- See Also:
-
getBase
public double getBase()Returns the base value for the bars.- Returns:
- The base value for the bars.
- See Also:
-
setBase
public void setBase(double base) Sets the base value for the bars and sends aRendererChangeEvent
to all registered listeners. The base value is not used if the dataset's y-interval is being used to determine the bar length.- Parameters:
base
- the new base value.- See Also:
-
getUseYInterval
public boolean getUseYInterval()Returns a flag that determines whether the y-interval from the dataset is used to calculate the length of each bar.- Returns:
- A boolean.
- See Also:
-
setUseYInterval
public void setUseYInterval(boolean use) Sets the flag that determines whether the y-interval from the dataset is used to calculate the length of each bar, and sends aRendererChangeEvent
to all registered listeners.- Parameters:
use
- the flag.- See Also:
-
getMargin
public double getMargin()Returns the margin which is a percentage amount by which the bars are trimmed.- Returns:
- The margin.
- See Also:
-
setMargin
public void setMargin(double margin) Sets the percentage amount by which the bars are trimmed and sends aRendererChangeEvent
to all registered listeners.- Parameters:
margin
- the new margin.- See Also:
-
isDrawBarOutline
public boolean isDrawBarOutline()Returns a flag that controls whether or not bar outlines are drawn.- Returns:
- A boolean.
- See Also:
-
setDrawBarOutline
public void setDrawBarOutline(boolean draw) Sets the flag that controls whether or not bar outlines are drawn and sends aRendererChangeEvent
to all registered listeners.- Parameters:
draw
- the flag.- See Also:
-
getGradientPaintTransformer
Returns the gradient paint transformer (an object used to transform gradient paint objects to fit each bar).- Returns:
- A transformer (
null
possible). - See Also:
-
setGradientPaintTransformer
Sets the gradient paint transformer and sends aRendererChangeEvent
to all registered listeners.- Parameters:
transformer
- the transformer (null
permitted).- See Also:
-
getLegendBar
Returns the shape used to represent bars in each legend item.- Returns:
- The shape used to represent bars in each legend item (never
null
). - See Also:
-
setLegendBar
Sets the shape used to represent bars in each legend item and sends aRendererChangeEvent
to all registered listeners.- Parameters:
bar
- the bar shape (null
not permitted).- See Also:
-
getPositiveItemLabelPositionFallback
Returns the fallback position for positive item labels that don't fit within a bar.- Returns:
- The fallback position (
null
possible). - See Also:
-
setPositiveItemLabelPositionFallback
Sets the fallback position for positive item labels that don't fit within a bar, and sends aRendererChangeEvent
to all registered listeners.- Parameters:
position
- the position (null
permitted).- See Also:
-
getNegativeItemLabelPositionFallback
Returns the fallback position for negative item labels that don't fit within a bar.- Returns:
- The fallback position (
null
possible). - See Also:
-
setNegativeItemLabelPositionFallback
Sets the fallback position for negative item labels that don't fit within a bar, and sends aRendererChangeEvent
to all registered listeners.- Parameters:
position
- the position (null
permitted).- See Also:
-
getBarPainter
Returns the bar painter.- Returns:
- The bar painter (never
null
).
-
setBarPainter
Sets the bar painter and sends aRendererChangeEvent
to all registered listeners.- Parameters:
painter
- the painter (null
not permitted).
-
getShadowsVisible
public boolean getShadowsVisible()Returns the flag that controls whether or not shadows are drawn for the bars.- Returns:
- A boolean.
-
setShadowVisible
public void setShadowVisible(boolean visible) Sets the flag that controls whether or not the renderer draws shadows for the bars, and sends aRendererChangeEvent
to all registered listeners.- Parameters:
visible
- the new flag value.
-
getShadowXOffset
public double getShadowXOffset()Returns the shadow x-offset.- Returns:
- The shadow x-offset.
-
setShadowXOffset
public void setShadowXOffset(double offset) Sets the x-offset for the bar shadow and sends aRendererChangeEvent
to all registered listeners.- Parameters:
offset
- the offset.
-
getShadowYOffset
public double getShadowYOffset()Returns the shadow y-offset.- Returns:
- The shadow y-offset.
-
setShadowYOffset
public void setShadowYOffset(double offset) Sets the y-offset for the bar shadow and sends aRendererChangeEvent
to all registered listeners.- Parameters:
offset
- the offset.
-
getBarAlignmentFactor
public double getBarAlignmentFactor()Returns the bar alignment factor.- Returns:
- The bar alignment factor.
-
setBarAlignmentFactor
public void setBarAlignmentFactor(double factor) Sets the bar alignment factor and sends aRendererChangeEvent
to all registered listeners. If the alignment factor is outside the range 0.0 to 1.0, no alignment will be performed by the renderer.- Parameters:
factor
- the factor.
-
initialise
public XYItemRendererState initialise(Graphics2D g2, Rectangle2D dataArea, XYPlot plot, XYDataset dataset, PlotRenderingInfo info) Initialises the renderer and returns a state object that should be passed to all subsequent calls to the drawItem() method. Here we calculate the Java2D y-coordinate for zero, since all the bars have their bases fixed at zero.- Specified by:
initialise
in interfaceXYItemRenderer
- Overrides:
initialise
in classAbstractXYItemRenderer
- Parameters:
g2
- the graphics device.dataArea
- the area inside the axes.plot
- the plot.dataset
- the data.info
- an optional info collection object to return data back to the caller.- Returns:
- A state object.
-
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.
-
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 plot is being drawn.info
- collects information about the drawing.plot
- the plot (can be used to obtain standard color information etc).domainAxis
- the domain axis.rangeAxis
- the range 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.
-
drawItemLabel
protected void drawItemLabel(Graphics2D g2, XYDataset dataset, int series, int item, XYPlot plot, XYItemLabelGenerator generator, Rectangle2D bar, boolean negative) Draws an item label. This method is provided as an alternative toAbstractXYItemRenderer.drawItemLabel(Graphics2D, PlotOrientation, XYDataset, int, int, double, double, boolean)
so that the bar can be used to calculate the label anchor point.- Parameters:
g2
- the graphics device.dataset
- the dataset.series
- the series index.item
- the item index.plot
- the plot.generator
- the label generator (null
permitted, in which case the method does nothing, just returns).bar
- the bar.negative
- a flag indicating a negative value.
-
findDomainBounds
Returns the lower and upper bounds (range) of the x-values in the specified dataset. Since this renderer uses the x-interval in the dataset, this is taken into account for the range.- Specified by:
findDomainBounds
in interfaceXYItemRenderer
- Overrides:
findDomainBounds
in classAbstractXYItemRenderer
- Parameters:
dataset
- the dataset (null
permitted).- Returns:
- The range (
null
if the dataset isnull
or empty). - See Also:
-
findRangeBounds
Returns the lower and upper bounds (range) of the y-values in the specified dataset. If the renderer is plotting the y-interval from the dataset, this is taken into account for the range.- Specified by:
findRangeBounds
in interfaceXYItemRenderer
- Overrides:
findRangeBounds
in classAbstractXYItemRenderer
- Parameters:
dataset
- the dataset (null
permitted).- Returns:
- The range (
null
if the dataset isnull
or empty). - See Also:
-
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.
-
equals
Tests this renderer for equality with an arbitrary object.- Overrides:
equals
in classAbstractXYItemRenderer
- Parameters:
obj
- the object to test against (null
permitted).- Returns:
- A boolean.
-