Class CandlestickSeries
Open/high/low/close prices drawn as candlesticks, OHLC bars or Heikin-Ashi candles.
A rising period (close at or above open) is drawn in the theme's positive colour and a falling
one in its negative colour. Pair it with a SessionTimeAxis to skip weekends, or with a
TimeAxis to keep calendar spacing.
Chart chart = new Chart();
long day = 24L * 60 * 60 * 1000;
long[] timestamps = {0, day, 4 * day};
double[] open = {10, 11, 12}, high = {12, 13, 14}, low = {9, 10, 11}, close = {11, 12, 13};
CandlestickSeries prices = new CandlestickSeries("ACME");
prices.setOhlc(null, open, high, low, close);
chart.setXAxis(new SessionTimeAxis(Axis.BOTTOM, timestamps));
chart.addSeries(prices);

-
Field Summary
FieldsModifier and TypeFieldDescriptionstatic final intFilled bodies with wicks.static final intCandles of Heikin-Ashi averaged prices, which smooth out noise to show the trend.static final intA vertical high-low line with open and close ticks. -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionadd(double x, double y) Appends a point.addOhlc(double x, double open, double high, double low, double close) Appends one period, for streaming quotes.protected voidDrops the cached Heikin-Ashi values: they depend on every candle, so any change to the data (an add, a slide, aset, anupdateLast) makes them stale, not only a change of length.formatTooltip(ChartContext ctx, ChartPoint p) The tooltip row for a point: the series or point name and its formatted value.doublegetClose(int i) Closing price of periodi.doublegetHigh(int i) Highest price of periodi.doublegetLow(int i) Lowest price of periodi.doublegetOpen(int i) Opening price of periodi.intgetStyle()The drawing style.double[]The extent of the data along x,{min, max}, or null when empty or not cartesian.double[]The extent of the data along y,{min, max}, or null when empty or not cartesian.double[][]Computes Heikin-Ashi values,{open, high, low, close}arrays.hitTest(ChartContext ctx, int x, int y, int radius) Finds the data point nearest a screen position.voidpaint(ChartContext ctx) Paints the series.voidpaintLegendSymbol(Graphics g, int x, int y, int size) Paints the legend swatch.setBodyFraction(float f) The fraction of each slot a body takes, 0.1 to 1.setColors(int up, int down) Overrides the theme's rising and falling colours.setOhlc(double[] x, double[] open, double[] high, double[] low, double[] close) Replaces all prices.setStyle(int style) Chooses candles, OHLC bars or Heikin-Ashi candles.protected StringtableValue(int i) The text of pointiin the accessible data table.updateLast(double price) Updates the last period in place, as a live tick does to the current candle.Methods inherited from class XYSeries
add, addRow, animatedAux, animatedBase, animatedY, auxDefault, captureEntryStart, captureTransitionStart, clear, collectTableRows, consumesStackBase, getAux, getBase, getMinXSpacing, getPoint, getPointCount, getStackGroup, getX, getXBoundsWithin, getY, hasOwnBase, isAscending, isAuxRelative, isCartesian, isGapAt, lowerBound, nearestIndexOfX, nearestScreenIndex, screenPosition, set, setData, setMaxPoints, setRows, setStackGroup, setValues, size, targetBase, transitionEnded, visibleRangeMethods inherited from class Series
attached, detached, formatValue, getChart, getColor, getLegendEntryCount, getLegendEntryName, getName, getSelectablePointCount, getValueFormatter, getVisibilityFraction, handleTap, isGap, isLegendEntryVisible, isPointCountFromLayout, isSecondaryAxis, isShowValues, isVisible, lerp, paintLegendEntrySymbol, repaintChart, setColor, setName, setSecondaryAxis, setShowValues, setValueFormatter, setVisible, toggleLegendEntry
-
Field Details
-
CANDLES
public static final int CANDLESFilled bodies with wicks.- See Also:
-
OHLC_BARS
public static final int OHLC_BARSA vertical high-low line with open and close ticks.- See Also:
-
HEIKIN_ASHI
public static final int HEIKIN_ASHICandles of Heikin-Ashi averaged prices, which smooth out noise to show the trend.- See Also:
-
-
Constructor Details
-
CandlestickSeries
Creates an empty series.
Parameters
name: the series name
-
-
Method Details
-
setOhlc
public CandlestickSeries setOhlc(double[] x, double[] open, double[] high, double[] low, double[] close) Replaces all prices.
Parameters
-
x: the x value of each period (a time, or an index forSessionTimeAxis); null for 0, 1, 2... -
open: opening prices -
high: highest prices -
low: lowest prices -
close: closing prices
Returns
this series
-
-
addOhlc
Appends one period, for streaming quotes.
Parameters
-
x: the period's x value -
open: the opening price -
high: the highest price -
low: the lowest price -
close: the closing price
Returns
this series
-
-
add
-
updateLast
Updates the last period in place, as a live tick does to the current candle.
Parameters
price: the latest traded price
Returns
this series
-
setStyle
Chooses candles, OHLC bars or Heikin-Ashi candles.
Parameters
style:CANDLES,OHLC_BARSorHEIKIN_ASHI
Returns
this series
-
getStyle
public int getStyle()The drawing style. -
setBodyFraction
The fraction of each slot a body takes, 0.1 to 1.
Parameters
f: the fraction
Returns
this series
-
setColors
Overrides the theme's rising and falling colours.
Parameters
-
up: colour of rising periods -
down: colour of falling periods
Returns
this series
-
-
getOpen
public double getOpen(int i) Opening price of periodi. -
getHigh
public double getHigh(int i) Highest price of periodi. -
getLow
public double getLow(int i) Lowest price of periodi. -
getClose
public double getClose(int i) Closing price of periodi. -
heikinAshi
public double[][] heikinAshi()Computes Heikin-Ashi values,
{open, high, low, close}arrays.Returns
the averaged prices for every period
-
dataChanged
protected void dataChanged()Drops the cached Heikin-Ashi values: they depend on every candle, so any change to the data (an add, a slide, aset, anupdateLast) makes them stale, not only a change of length.- Overrides:
dataChangedin classXYSeries
-
getYBounds
public double[] getYBounds()Description copied from class:SeriesThe extent of the data along y,{min, max}, or null when empty or not cartesian.- Overrides:
getYBoundsin classXYSeries
-
getXBounds
public double[] getXBounds()Description copied from class:SeriesThe extent of the data along x,{min, max}, or null when empty or not cartesian.- Overrides:
getXBoundsin classXYSeries
-
paint
Description copied from class:SeriesPaints the series.
Parameters
ctx: the current frame: graphics, plot area, axes and animation progress
-
hitTest
Description copied from class:SeriesFinds the data point nearest a screen position.
Parameters
-
ctx: the frame the series was last painted in -
x: chart relative x -
y: chart relative y -
radius: how far from the point a touch may land and still hit it
Returns
the point, or null
-
-
formatTooltip
Description copied from class:SeriesThe tooltip row for a point: the series or point name and its formatted value. Series with several values per point (open/high/low/close, ranges, box plots) override this.
Parameters
-
ctx: the last paint context -
p: the point
Returns
one line of text
- Overrides:
formatTooltipin classSeries
-
-
paintLegendSymbol
Description copied from class:SeriesPaints the legend swatch.
Parameters
-
g: graphics -
x: swatch left -
y: swatch top -
size: swatch size
- Overrides:
paintLegendSymbolin classSeries
-
-
tableValue
Description copied from class:XYSeriesThe text of point
iin the accessible data table.Parameters
i: the point index
Returns
the formatted value
- Overrides:
tableValuein classXYSeries
-