Class CandlestickRenderer

    • Field Detail

      • serialVersionUID

        private static final long serialVersionUID
        For serialization.
        See Also:
        Constant Field Values
      • WIDTHMETHOD_AVERAGE

        public static final int WIDTHMETHOD_AVERAGE
        The average width method.
        See Also:
        Constant Field Values
      • WIDTHMETHOD_SMALLEST

        public static final int WIDTHMETHOD_SMALLEST
        The smallest width method.
        See Also:
        Constant Field Values
      • WIDTHMETHOD_INTERVALDATA

        public static final int WIDTHMETHOD_INTERVALDATA
        The interval data method.
        See Also:
        Constant Field Values
      • autoWidthMethod

        private int autoWidthMethod
        The method of automatically calculating the candle width.
      • autoWidthFactor

        private double autoWidthFactor
        The number (generally between 0.0 and 1.0) by which the available space automatically calculated for the candles will be multiplied to determine the actual width to use.
      • autoWidthGap

        private double autoWidthGap
        The minimum gap between one candle and the next
      • candleWidth

        private double candleWidth
        The candle width.
      • maxCandleWidthInMilliseconds

        private double maxCandleWidthInMilliseconds
        The maximum candlewidth in milliseconds.
      • maxCandleWidth

        private double maxCandleWidth
        Temporary storage for the maximum candle width.
      • upPaint

        private transient java.awt.Paint upPaint
        The paint used to fill the candle when the price moved up from open to close.
      • downPaint

        private transient java.awt.Paint downPaint
        The paint used to fill the candle when the price moved down from open to close.
      • drawVolume

        private boolean drawVolume
        A flag controlling whether or not volume bars are drawn on the chart.
      • volumePaint

        private transient java.awt.Paint volumePaint
        The paint used to fill the volume bars (if they are visible). Once initialised, this field should never be set to null.
      • maxVolume

        private transient double maxVolume
        Temporary storage for the maximum volume.
      • useOutlinePaint

        private boolean useOutlinePaint
        A flag that controls whether or not the renderer's outline paint is used to draw the outline of the candlestick. The default value is false to avoid a change of behaviour for existing code.
    • Constructor Detail

      • 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 Detail

      • getCandleWidth

        public double getCandleWidth()
        Returns the width of each candle.
        Returns:
        The candle width.
        See Also:
        setCandleWidth(double)
      • getMaxCandleWidthInMilliseconds

        public double getMaxCandleWidthInMilliseconds()
        Returns the maximum width (in milliseconds) of each candle.
        Returns:
        The maximum candle width in milliseconds.
        See Also:
        setMaxCandleWidthInMilliseconds(double)
      • getAutoWidthMethod

        public int getAutoWidthMethod()
        Returns the method of automatically calculating the candle width.
        Returns:
        The method of automatically calculating the candle width.
        See Also:
        setAutoWidthMethod(int)
      • 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).
        See Also:
        setAutoWidthFactor(double)
      • 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.
        See Also:
        setAutoWidthGap(double)
      • getUpPaint

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

        public void setUpPaint​(java.awt.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()
      • getDownPaint

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

        public void setDownPaint​(java.awt.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).
      • getDrawVolume

        public boolean getDrawVolume()
        Returns a flag indicating whether or not volume bars are drawn on the chart.
        Returns:
        A boolean.
        See Also:
        setDrawVolume(boolean)
      • 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.
        See Also:
        getDrawVolume()
      • getVolumePaint

        public java.awt.Paint getVolumePaint()
        Returns the paint that is used to fill the volume bars if they are visible.
        Returns:
        The paint (never null).
        See Also:
        setVolumePaint(Paint)
      • setVolumePaint

        public void setVolumePaint​(java.awt.Paint paint)
        Sets the paint used to fill the volume bars, and sends a RendererChangeEvent to all registered listeners.
        Parameters:
        paint - the paint (null not permitted).
        See Also:
        getVolumePaint(), getDrawVolume()
      • 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.
        See Also:
        setUseOutlinePaint(boolean)
      • 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.
        See Also:
        getUseOutlinePaint()
      • initialise

        public XYItemRendererState initialise​(java.awt.Graphics2D g2,
                                              java.awt.geom.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 class 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.
      • 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 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.
      • equals

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

        public java.lang.Object clone()
                               throws java.lang.CloneNotSupportedException
        Returns a clone of the renderer.
        Specified by:
        clone in interface PublicCloneable
        Overrides:
        clone in class AbstractXYItemRenderer
        Returns:
        A clone.
        Throws:
        java.lang.CloneNotSupportedException - if the renderer cannot be cloned.
      • writeObject

        private void writeObject​(java.io.ObjectOutputStream stream)
                          throws java.io.IOException
        Provides serialization support.
        Parameters:
        stream - the output stream.
        Throws:
        java.io.IOException - if there is an I/O error.
      • readObject

        private void readObject​(java.io.ObjectInputStream stream)
                         throws java.io.IOException,
                                java.lang.ClassNotFoundException
        Provides 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.