Client API. The Codename One framework your app is built on: this runs on the device, not in a backend.
public class 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
From Axis
getPosition, setPosition, isVertical, getTitle, setTitle, isVisible, setVisible, isGridVisible, setGridVisible, getFormatter, setFormatter, setRange, isMinFixed, isMaxFixed, setIncludeZero, isIncludeZero, setMaxZoom, isZoomEnabled, setZoomEnabled, flatPad, getDataMin, getDataMax, getVisibleMin, getVisibleMax, setVisibleRange, setDisplayRange, restoreViewport, resetViewport, isZoomed, zoom, pan, forward, inverse, toNormalized, fromNormalized, format, formatNumber
Constructor details
SessionTimeAxis
public SessionTimeAxis(int position, long[] times)Parameters
positionint- one of the
Axisposition constants timeslong[]- 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
timeslong[]- the timestamp of each bar in milliseconds, ascending
Returns
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
timelong- the new bar’s timestamp in milliseconds, not before the previous one
Returns
setMaxTimes
public SessionTimeAxis setMaxTimes(int n)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
nint- the maximum number of timestamps, or 0 for no limit
Returns
getFirstIndex
public int getFirstIndex()setMaxTimes drops one.Returns
timeAt
public long timeAt(double index)index, extrapolated past either end.Parameters
indexdouble- the bar index
Returns
setDataBounds
public void setDataBounds(double min, double max)Parameters
mindouble- smallest value of any visible series
maxdouble- largest value of any visible series
adjustBounds
protected double[] adjustBounds(double min, double max)Parameters
mindouble- the raw minimum
maxdouble- the raw maximum
Returns
{min, max} to useticks
public double[] ticks(int maxCount)Parameters
maxCountint- the most ticks the measured label size allows
Returns
defaultFormat
protected String defaultFormat(double value, double step)