org.jfree.chart.renderer.xy

Class CandlestickRenderer

Implemented Interfaces:
Cloneable, LegendItemSource, PublicCloneable, Serializable, XYItemRenderer

public class CandlestickRenderer
extends AbstractXYItemRenderer
implements XYItemRenderer, Cloneable, PublicCloneable, Serializable

A renderer that draws candlesticks on an XYPlot (requires a OHLCDataset).

This renderer does not include code to calculate the crosshair point for the plot.

Field Summary

static int
WIDTHMETHOD_AVERAGE
The average width method.
static int
WIDTHMETHOD_INTERVALDATA
The interval data method.
static int
WIDTHMETHOD_SMALLEST
The smallest width method.

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

CandlestickRenderer()
Creates a new renderer for candlestick charts.
CandlestickRenderer(double candleWidth)
Creates a new renderer for candlestick charts.
CandlestickRenderer(double candleWidth, boolean drawVolume, XYToolTipGenerator toolTipGenerator)
Creates a new renderer for candlestick charts.

Method Summary

Object
clone()
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.
boolean
drawVolume()
Deprecated. As of 1.0.5, you should use the getDrawVolume() method.
boolean
equals(Object obj)
Tests this renderer for equality with another object.
double
getAutoWidthFactor()
Returns the factor by which the available space automatically calculated for the candles will be multiplied to determine the actual width to use.
double
getAutoWidthGap()
Returns the amount of space to leave on the left and right of each candle when automatically calculating widths.
int
getAutoWidthMethod()
Returns the method of automatically calculating the candle width.
double
getCandleWidth()
Returns the width of each candle.
Paint
getDownPaint()
Returns the paint used to fill candles when the price moves down from open to close.
boolean
getDrawVolume()
Returns a flag indicating whether or not volume bars are drawn on the chart.
double
getMaxCandleWidthInMilliseconds()
Returns the maximum width (in milliseconds) of each candle.
Paint
getUpPaint()
Returns the paint used to fill candles when the price moves up from open to close.
boolean
getUseOutlinePaint()
Returns the flag that controls whether or not the renderer's outline paint is used to draw the candlestick outline.
XYItemRendererState
initialise(Graphics2D g2, Rectangle2D dataArea, XYPlot plot, XYDataset dataset, PlotRenderingInfo info)
Initialises the renderer then returns the number of 'passes' through the data that the renderer will require (usually just one).
void
setAutoWidthFactor(double autoWidthFactor)
Sets the factor by which the available space automatically calculated for the candles will be multiplied to determine the actual width to use.
void
setAutoWidthGap(double autoWidthGap)
Sets the amount of space to leave on the left and right of each candle when automatically calculating widths.
void
setAutoWidthMethod(int autoWidthMethod)
Sets the method of automatically calculating the candle width.
void
setCandleWidth(double width)
Sets the candle width.
void
setDownPaint(Paint paint)
Sets the paint used to fill candles when the price moves down from open to close and sends a RendererChangeEvent to all registered listeners.
void
setDrawVolume(boolean flag)
Sets a flag that controls whether or not volume bars are drawn in the background and sends a RendererChangeEvent to all registered listeners.
void
setMaxCandleWidthInMilliseconds(double millis)
Sets the maximum candle width (in milliseconds).
void
setUpPaint(Paint paint)
Sets the paint used to fill candles when the price moves up from open to close and sends a RendererChangeEvent to all registered listeners.
void
setUseOutlinePaint(boolean use)
Sets the flag that controls whether or not the renderer's outline paint is used to draw the candlestick outline, and sends a RendererChangeEvent to all registered listeners.

Methods inherited from class org.jfree.chart.renderer.xy.AbstractXYItemRenderer

addAnnotation, addAnnotation, addEntity, calculateDomainMarkerTextAnchorPoint, clone, drawAnnotations, drawDomainGridLine, drawDomainLine, drawDomainMarker, drawItemLabel, drawRangeLine, drawRangeMarker, equals, fillDomainGridBand, fillRangeGridBand, findDomainBounds, findRangeBounds, getBaseItemLabelGenerator, getBaseToolTipGenerator, getDefaultEntityRadius, getDrawingSupplier, getItemLabelGenerator, getItemLabelGenerator, getLegendItem, getLegendItemLabelGenerator, getLegendItemToolTipGenerator, getLegendItemURLGenerator, getLegendItems, getPassCount, getPlot, getSeriesItemLabelGenerator, getSeriesToolTipGenerator, getToolTipGenerator, getToolTipGenerator, getURLGenerator, initialise, removeAnnotation, removeAnnotations, setBaseItemLabelGenerator, setBaseToolTipGenerator, setDefaultEntityRadius, setItemLabelGenerator, setLegendItemLabelGenerator, setLegendItemToolTipGenerator, setLegendItemURLGenerator, setPlot, setSeriesItemLabelGenerator, setSeriesToolTipGenerator, setToolTipGenerator, setURLGenerator, updateCrosshairValues, updateCrosshairValues

Methods inherited from class org.jfree.chart.renderer.AbstractRenderer

addChangeListener, calculateLabelAnchorPoint, clone, equals, fireChangeEvent, getBaseCreateEntities, getBaseFillPaint, getBaseItemLabelFont, getBaseItemLabelPaint, getBaseItemLabelsVisible, getBaseNegativeItemLabelPosition, getBaseOutlinePaint, getBaseOutlineStroke, getBasePaint, getBasePositiveItemLabelPosition, getBaseSeriesVisible, getBaseSeriesVisibleInLegend, getBaseShape, getBaseStroke, getCreateEntities, getDrawingSupplier, getItemCreateEntity, getItemFillPaint, getItemLabelAnchorOffset, getItemLabelFont, getItemLabelFont, getItemLabelPaint, getItemLabelPaint, getItemOutlinePaint, getItemOutlineStroke, getItemPaint, getItemShape, getItemStroke, getItemVisible, getNegativeItemLabelPosition, getNegativeItemLabelPosition, getPositiveItemLabelPosition, getPositiveItemLabelPosition, getSeriesCreateEntities, getSeriesFillPaint, getSeriesItemLabelFont, getSeriesItemLabelPaint, getSeriesNegativeItemLabelPosition, getSeriesOutlinePaint, getSeriesOutlineStroke, getSeriesPaint, getSeriesPositiveItemLabelPosition, getSeriesShape, getSeriesStroke, getSeriesVisible, getSeriesVisible, getSeriesVisibleInLegend, getSeriesVisibleInLegend, hasListener, hashCode, isItemLabelVisible, isSeriesItemLabelsVisible, isSeriesVisible, isSeriesVisibleInLegend, notifyListeners, removeChangeListener, setBaseCreateEntities, setBaseCreateEntities, setBaseFillPaint, setBaseFillPaint, setBaseItemLabelFont, setBaseItemLabelFont, setBaseItemLabelPaint, setBaseItemLabelPaint, setBaseItemLabelsVisible, setBaseItemLabelsVisible, setBaseItemLabelsVisible, setBaseNegativeItemLabelPosition, setBaseNegativeItemLabelPosition, setBaseOutlinePaint, setBaseOutlinePaint, setBaseOutlineStroke, setBaseOutlineStroke, setBasePaint, setBasePaint, setBasePositiveItemLabelPosition, setBasePositiveItemLabelPosition, setBaseSeriesVisible, setBaseSeriesVisible, setBaseSeriesVisibleInLegend, setBaseSeriesVisibleInLegend, setBaseShape, setBaseShape, setBaseStroke, setBaseStroke, setCreateEntities, setCreateEntities, setFillPaint, setFillPaint, setItemLabelAnchorOffset, setItemLabelFont, setItemLabelFont, setItemLabelPaint, setItemLabelPaint, setItemLabelsVisible, setItemLabelsVisible, setItemLabelsVisible, setNegativeItemLabelPosition, setNegativeItemLabelPosition, setOutlinePaint, setOutlinePaint, setOutlineStroke, setOutlineStroke, setPaint, setPaint, setPositiveItemLabelPosition, setPositiveItemLabelPosition, 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, setSeriesVisible, setSeriesVisible, setSeriesVisibleInLegend, setSeriesVisibleInLegend, setSeriesVisibleInLegend, setSeriesVisibleInLegend, setShape, setShape, setStroke, setStroke

Field Details

WIDTHMETHOD_AVERAGE

public static final int WIDTHMETHOD_AVERAGE
The average width method.
Field Value:
0

WIDTHMETHOD_INTERVALDATA

public static final int WIDTHMETHOD_INTERVALDATA
The interval data method.
Field Value:
2

WIDTHMETHOD_SMALLEST

public static final int WIDTHMETHOD_SMALLEST
The smallest width method.
Field Value:
1

Constructor Details

CandlestickRenderer

public CandlestickRenderer()
Creates a new renderer for candlestick charts.

CandlestickRenderer

public CandlestickRenderer(double candleWidth)
Creates a new renderer for candlestick charts.

Use -1 for the candle width if you prefer the width to be calculated automatically.

Parameters:
candleWidth - The candle width.

CandlestickRenderer

public CandlestickRenderer(double candleWidth,
                           boolean drawVolume,
                           XYToolTipGenerator toolTipGenerator)
Creates a new renderer for candlestick charts.

Use -1 for the candle width if you prefer the width to be calculated automatically.

Parameters:
candleWidth - the candle width.
drawVolume - a flag indicating whether or not volume bars should be drawn.
toolTipGenerator - the tool tip generator. null is none.

Method Details

clone

public Object clone()
            throws CloneNotSupportedException
Returns a clone of the renderer.
Overrides:
clone in interface AbstractXYItemRenderer
Returns:
A clone.

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 interface XYItemRenderer
Parameters:
g2 - the graphics device.
state - the renderer state.
dataArea - the area within which the plot is being drawn.
info - collects info 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.

drawVolume

public boolean drawVolume()

Deprecated. As of 1.0.5, you should use the getDrawVolume() method.

Returns a flag indicating whether or not volume bars are drawn on the chart.
Returns:
true if volume bars are drawn on the chart.

equals

public boolean equals(Object obj)
Tests this renderer for equality with another object.
Overrides:
equals in interface AbstractXYItemRenderer
Parameters:
obj - the object (null permitted).
Returns:
true or false.

getAutoWidthFactor

public double getAutoWidthFactor()
Returns the factor by which the available space automatically calculated for the candles will be multiplied to determine the actual width to use.
Returns:
The width factor (generally between 0.0 and 1.0).

getAutoWidthGap

public double getAutoWidthGap()
Returns the amount of space to leave on the left and right of each candle when automatically calculating widths.
Returns:
The gap.

getAutoWidthMethod

public int getAutoWidthMethod()
Returns the method of automatically calculating the candle width.
Returns:
The method of automatically calculating the candle width.

getCandleWidth

public double getCandleWidth()
Returns the width of each candle.
Returns:
The candle width.

getDownPaint

public Paint getDownPaint()
Returns the paint used to fill candles when the price moves down from open to close.
Returns:
The paint (possibly null).

getDrawVolume

public boolean getDrawVolume()
Returns a flag indicating whether or not volume bars are drawn on the chart.
Returns:
A boolean.
Since:
1.0.5

getMaxCandleWidthInMilliseconds

public double getMaxCandleWidthInMilliseconds()
Returns the maximum width (in milliseconds) of each candle.
Returns:
The maximum candle width in milliseconds.

getUpPaint

public Paint getUpPaint()
Returns the paint used to fill candles when the price moves up from open to close.
Returns:
The paint (possibly null).

getUseOutlinePaint

public boolean getUseOutlinePaint()
Returns the flag that controls whether or not the renderer's outline paint is used to draw the candlestick outline. The default value is false.
Returns:
A boolean.
Since:
1.0.5

initialise

public XYItemRendererState initialise(Graphics2D g2,
                                      Rectangle2D dataArea,
                                      XYPlot plot,
                                      XYDataset dataset,
                                      PlotRenderingInfo info)
Initialises the renderer then returns the number of 'passes' through the data that the renderer will require (usually just one). 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 interface XYItemRenderer
Overrides:
initialise in interface AbstractXYItemRenderer
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:
The number of passes the renderer requires.

setAutoWidthFactor

public void setAutoWidthFactor(double autoWidthFactor)
Sets the factor by which the available space automatically calculated for the candles will be multiplied to determine the actual width to use.
Parameters:
autoWidthFactor - The width factor (generally between 0.0 and 1.0).

setAutoWidthGap

public void setAutoWidthGap(double autoWidthGap)
Sets the amount of space to leave on the left and right of each candle when automatically calculating widths.
Parameters:
autoWidthGap - The gap.

setAutoWidthMethod

public void setAutoWidthMethod(int autoWidthMethod)
Sets the method of automatically calculating the candle width.

WIDTHMETHOD_AVERAGE: Divides the entire display (ignoring scale factor) by the number of items, and uses this as the available width.
WIDTHMETHOD_SMALLEST: Checks the interval between each item, and uses the smallest as the available width.
WIDTHMETHOD_INTERVALDATA: Assumes that the dataset supports the IntervalXYDataset interface, and uses the startXValue - endXValue as the available width.

Parameters:
autoWidthMethod - The method of automatically calculating the candle width.

setCandleWidth

public void setCandleWidth(double width)
Sets the candle width.

If you set the width to a negative value, the renderer will calculate the candle width automatically based on the space available on the chart.

Parameters:
width - The width.

setDownPaint

public void setDownPaint(Paint paint)
Sets the paint used to fill candles when the price moves down from open to close and sends a RendererChangeEvent to all registered listeners.
Parameters:
paint - The paint (null permitted).

setDrawVolume

public void setDrawVolume(boolean flag)
Sets a flag that controls whether or not volume bars are drawn in the background and sends a RendererChangeEvent to all registered listeners.
Parameters:
flag - the flag.

setMaxCandleWidthInMilliseconds

public void setMaxCandleWidthInMilliseconds(double millis)
Sets the maximum candle width (in milliseconds).
Parameters:
millis - The maximum width.

setUpPaint

public void setUpPaint(Paint paint)
Sets the paint used to fill candles when the price moves up from open to close and sends a RendererChangeEvent to all registered listeners.
Parameters:
paint - the paint (null permitted).
See Also:
getUpPaint()

setUseOutlinePaint

public void setUseOutlinePaint(boolean use)
Sets the flag that controls whether or not the renderer's outline paint is used to draw the candlestick outline, and sends a RendererChangeEvent to all registered listeners.
Parameters:
use - the new flag value.
Since:
1.0.5