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));
-
Field Summary
-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionaddTime(long time) Appends the timestamp of the next bar, for a series that grows withXYSeries.add(y).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.protected StringdefaultFormat(double value, double step) The axis' built in formatting; numbers are grouped and localized.intThe bar index of the oldest stored timestamp: 0 untilsetMaxTimesdrops one.voidsetDataBounds(double min, double max) Called by the chart with the extent of the data on this axis.setMaxTimes(int n) Keeps only the newestntimestamps, dropping the oldest asaddTimeappends, the wayXYSeries.setMaxPoints(n)drops the oldest bar.setTimes(long[] times) Replaces the timestamps.double[]ticks(int maxCount) Ticks for the visible range.longtimeAt(double index) The timestamp of barindex, extrapolated past either end.Methods inherited from class Axis
flatPad, format, formatNumber, forward, fromNormalized, getDataMax, getDataMin, getFormatter, getPosition, getTitle, getVisibleMax, getVisibleMin, inverse, isGridVisible, isIncludeZero, isMaxFixed, isMinFixed, isVertical, isVisible, isZoomed, isZoomEnabled, pan, resetViewport, restoreViewport, setDisplayRange, setFormatter, setGridVisible, setIncludeZero, setMaxZoom, setPosition, setRange, setTitle, setVisible, setVisibleRange, setZoomEnabled, toNormalized, zoom
-
Constructor Details
-
SessionTimeAxis
public SessionTimeAxis(int position, long[] times) Creates the axis.
Parameters
-
position: one of theAxisposition constants -
times: the timestamp of each bar in milliseconds, ascending
-
-
-
Method Details
-
setTimes
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: callrepaint()on the chart, or change the series data in the same step, which repaints it.Parameters
times: the timestamp of each bar in milliseconds, ascending
Returns
this axis
-
addTime
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: callrepaint()on the chart, or change the series data in the same step, which repaints it.Parameters
time: the new bar's timestamp in milliseconds, not before the previous one
Returns
this axis
-
setMaxTimes
Keeps only the newest
ntimestamps, dropping the oldest asaddTimeappends, the wayXYSeries.setMaxPoints(n)drops the oldest bar. Each dropped timestamp movesgetFirstIndex()up by one, so the remaining bars keep their indices. LikesetTimes, this does not repaint the chart.Parameters
n: 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
setMaxTimesdrops 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: the bar index
Returns
milliseconds since the epoch
-
setDataBounds
public void setDataBounds(double min, double max) Description copied from class:AxisCalled by the chart with the extent of the data on this axis.
Parameters
-
min: smallest value of any visible series -
max: largest value of any visible series
- Overrides:
setDataBoundsin classAxis
-
-
adjustBounds
protected double[] adjustBounds(double min, double max) Description copied from class:AxisLets 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: the raw minimum -
max: the raw maximum
Returns
{min, max}to use- Overrides:
adjustBoundsin classAxis
-
-
ticks
-
defaultFormat
Description copied from class:AxisThe axis' built in formatting; numbers are grouped and localized.- Overrides:
defaultFormatin classAxis
-