Client API. The Codename One framework your app is built on: this runs on the device, not in a backend.

public class SessionTimeAxis

  1. Object
  2. Axis
  3. SessionTimeAxis

A time axis that skips the gaps between sessions: weekends, holidays, overnight hours.

Series on this axis use the index of each bar as their x value (0, 1, 2…) and the axis maps every index to its timestamp for labelling, the way trading charts do. Each bar is one slot wide no matter how much time separates it from the previous one, so a Monday candle sits right next to Friday’s.

Live data. A streaming series appends with XYSeries.add(y), which gives each new bar the next index, and with setMaxPoints(n) drops its oldest bar, so its first index climbs past 0. Follow it by calling addTime(long) with each bar’s timestamp, and setMaxTimes(n) with the same n: the axis then remembers the index of its first stored timestamp (getFirstIndex()) and labels the climbing indices with the times that belong to them.

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};
SessionTimeAxis axis = new SessionTimeAxis(Axis.BOTTOM, timestamps);
chart.setXAxis(axis);
chart.addSeries(new CandlestickSeries("ACME").setOhlc(null, open, high, low, close));

Constructors

public SessionTimeAxis(int position, long[] times)Creates the axis.

Methods

public SessionTimeAxis setTimes(long[] times)Replaces the timestamps.
public SessionTimeAxis addTime(long time)Appends the timestamp of the next bar, for a series that grows with XYSeries.add(y).
public SessionTimeAxis setMaxTimes(int n)Keeps only the newest n timestamps, dropping the oldest as addTime appends, the way XYSeries.setMaxPoints(n) drops the oldest bar.
public int getFirstIndex()The bar index of the oldest stored timestamp: 0 until setMaxTimes drops one.
public long timeAt(double index)The timestamp of bar index, extrapolated past either end.
public void setDataBounds(double min, double max)Called by the chart with the extent of the data on this axis.
protected double[] adjustBounds(double min, double max)Lets a subclass pad or round the automatic bounds; the default rounds a numeric range outward to the nearest nice step so the outermost grid lines sit on the plot edge.
public double[] ticks(int maxCount)Ticks for the visible range.
protected String defaultFormat(double value, double step)The axis’ built in formatting; numbers are grouped and localized.

Inherited fields

Inherited methods

Constructor details

SessionTimeAxis

public SessionTimeAxis(int position, long[] times)
Creates the axis.

Parameters

position int
one of the Axis position constants
times long[]
the timestamp of each bar in milliseconds, ascending

Method details

setTimes

public SessionTimeAxis setTimes(long[] times)

Replaces the timestamps.

An axis does not know the chart it is on, so the chart is not repainted by this call, as with CategoryAxis.setCategories: call repaint() on the chart, or change the series data in the same step, which repaints it.

Parameters

times long[]
the timestamp of each bar in milliseconds, ascending

Returns

this axis

addTime

public SessionTimeAxis addTime(long time)

Appends the timestamp of the next bar, for a series that grows with XYSeries.add(y).

An axis does not know the chart it is on, so the chart is not repainted by this call, as with CategoryAxis.setCategories: call repaint() on the chart, or change the series data in the same step, which repaints it.

Parameters

time long
the new bar’s timestamp in milliseconds, not before the previous one

Returns

this axis

setMaxTimes

public SessionTimeAxis setMaxTimes(int n)
Keeps only the newest n timestamps, dropping the oldest as addTime appends, the way XYSeries.setMaxPoints(n) drops the oldest bar. Each dropped timestamp moves getFirstIndex() up by one, so the remaining bars keep their indices. Like setTimes, this does not repaint the chart.

Parameters

n int
the maximum number of timestamps, or 0 for no limit

Returns

this axis

getFirstIndex

public int getFirstIndex()
The bar index of the oldest stored timestamp: 0 until setMaxTimes drops one.

Returns

the index of the first timestamp

timeAt

public long timeAt(double index)
The timestamp of bar index, extrapolated past either end.

Parameters

index double
the bar index

Returns

milliseconds since the epoch

setDataBounds

public void setDataBounds(double min, double max)
Called by the chart with the extent of the data on this axis.

Parameters

min double
smallest value of any visible series
max double
largest value of any visible series

adjustBounds

protected double[] adjustBounds(double min, double max)
Lets a subclass pad or round the automatic bounds; the default rounds a numeric range outward to the nearest nice step so the outermost grid lines sit on the plot edge.

Parameters

min double
the raw minimum
max double
the raw maximum

Returns

{min, max} to use

ticks

public double[] ticks(int maxCount)
Ticks for the visible range.

Parameters

maxCount int
the most ticks the measured label size allows

Returns

ascending tick values

defaultFormat

protected String defaultFormat(double value, double step)
The axis’ built in formatting; numbers are grouped and localized.