Client API. The Codename One framework your app is built on: this runs on the device, not in a backend.
public 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);

Fields
public static final int CANDLES = 0 | Filled bodies with wicks. |
public static final int OHLC_BARS = 1 | A vertical high-low line with open and close ticks. |
public static final int HEIKIN_ASHI = 2 | Candles of Heikin-Ashi averaged prices, which smooth out noise to show the trend. |
Constructors
public CandlestickSeries(String name) | Creates an empty series. |
Methods
Inherited methods
From XYSeries
setRows, addRow, auxDefault, getAux, isCartesian, setData, setValues, add, set, clear, setMaxPoints, setStackGroup, getStackGroup, size, getX, getY, getBase, isGapAt, isAscending, nearestIndexOfX, animatedY, consumesStackBase, animatedAux, isAuxRelative, animatedBase, targetBase, hasOwnBase, captureTransitionStart, transitionEnded, captureEntryStart, getXBoundsWithin, getMinXSpacing, lowerBound, visibleRange, screenPosition, nearestScreenIndex, collectTableRows, getPointCount, getPoint
From Series
getName, setName, getColor, setColor, isVisible, setVisible, isSecondaryAxis, setSecondaryAxis, isShowValues, setShowValues, getValueFormatter, setValueFormatter, getChart, getSelectablePointCount, isPointCountFromLayout, getLegendEntryCount, getLegendEntryName, paintLegendEntrySymbol, isLegendEntryVisible, toggleLegendEntry, formatValue, handleTap, attached, detached, repaintChart, getVisibilityFraction, isGap, lerp
Field details
CANDLES
public static final int CANDLES = 0OHLC_BARS
public static final int OHLC_BARS = 1HEIKIN_ASHI
public static final int HEIKIN_ASHI = 2Constructor details
CandlestickSeries
public CandlestickSeries(String name)Parameters
nameString- the series name
Method details
setOhlc
public CandlestickSeries setOhlc(double[] x, double[] open, double[] high, double[] low, double[] close)Parameters
xdouble[]- the x value of each period (a time, or an index for
SessionTimeAxis); null for 0, 1, 2… opendouble[]- opening prices
highdouble[]- highest prices
lowdouble[]- lowest prices
closedouble[]- closing prices
Returns
addOhlc
public CandlestickSeries addOhlc(double x, double open, double high, double low, double close)Parameters
xdouble- the period’s x value
opendouble- the opening price
highdouble- the highest price
lowdouble- the lowest price
closedouble- the closing price
Returns
add
public XYSeries add(double x, double y)setMaxPoints the oldest point drops off, for real time data.updateLast
public CandlestickSeries updateLast(double price)Parameters
pricedouble- the latest traded price
Returns
setStyle
public CandlestickSeries setStyle(int style)Parameters
styleintCANDLES,OHLC_BARSorHEIKIN_ASHI
Returns
getStyle
public int getStyle()setBodyFraction
public CandlestickSeries setBodyFraction(float f)Parameters
ffloat- the fraction
Returns
setColors
public CandlestickSeries setColors(int up, int down)Parameters
upint- colour of rising periods
downint- colour of falling periods
Returns
getOpen
public double getOpen(int i)i.getHigh
public double getHigh(int i)i.getLow
public double getLow(int i)i.getClose
public double getClose(int i)i.heikinAshi
public double[][] heikinAshi(){open, high, low, close} arrays.Returns
dataChanged
protected void dataChanged()set, an updateLast) makes them stale, not only a change of length.getYBounds
public double[] getYBounds(){min, max}, or null when empty or not cartesian.getXBounds
public double[] getXBounds(){min, max}, or null when empty or not cartesian.paint
public void paint(ChartContext ctx)Parameters
ctxChartContext- the current frame: graphics, plot area, axes and animation progress
hitTest
public ChartPoint hitTest(ChartContext ctx, int x, int y, int radius)Parameters
ctxChartContext- the frame the series was last painted in
xint- chart relative x
yint- chart relative y
radiusint- how far from the point a touch may land and still hit it
Returns
formatTooltip
public String formatTooltip(ChartContext ctx, ChartPoint p)Parameters
ctxChartContext- the last paint context
pChartPoint- the point
Returns
paintLegendSymbol
public void paintLegendSymbol(Graphics g, int x, int y, int size)Parameters
gGraphics- graphics
xint- swatch left
yint- swatch top
sizeint- swatch size
tableValue
protected String tableValue(int i)i in the accessible data table.Parameters
iint- the point index