Client API. The Codename One framework your app is built on: this runs on the device, not in a backend.
public abstract class XYSeries
Known subtypesBarSeries, BoxPlotSeries, CandlestickSeries, ErrorBarSeries, LineSeries, ScatterSeries
A series of (x, y) points in primitive arrays. A NaN y is a gap: lines break there
and bars are left out.
Series sharing a stack group are drawn on top of each other, each point resting on the sum of the earlier series at the same index.
Constructors
protected XYSeries(String name) | Creates an empty series. |
protected XYSeries(String name, int auxChannels) | Creates a series that keeps auxChannels extra values beside each y. |
Methods
protected void setRows(double[] x, double[] y, double[][] channels) | Replaces all points, each with its extra values. |
protected void addRow(double x, double y, double[] values) | Appends one point with its extra values, sliding the window when a maximum is set. |
protected double auxDefault(int channel, double y) | |
protected double getAux(int channel, int i) | |
public boolean isCartesian() | True for series drawn against x and y axes; false for pies, treemaps and other series that fill the plot themselves. |
public XYSeries setData(double[] x, double[] y) | Replaces all data. |
public XYSeries setValues(double... y) | Replaces all data with values at x = 0, 1, 2 … |
public XYSeries add(double y) | Appends a point at the next index. |
public XYSeries add(double x, double y) | Appends a point. |
public XYSeries set(int index, double y) | Changes the value at index. |
public XYSeries clear() | Removes every point. |
public XYSeries setMaxPoints(int n) | Keeps at most n points, dropping the oldest as new ones arrive; 0 keeps all. |
public XYSeries setStackGroup(String group) | Stacks this series on earlier ones sharing the same group name; null for none. |
public String getStackGroup() | The stack group, or null. |
public int size() | The number of points. |
public double getX(int i) | The x value at i. |
public double getY(int i) | The y value at i. |
public double getBase(int i) | The base this series’ point i rests on: 0, or the stacked sum of the earlier series in its group. |
protected void dataChanged() | Tells the chart this series’ data changed, which animates the new values in. |
public boolean isGapAt(int i) | True when point i has no value to show: its x or its y is NaN or infinite. |
public boolean isAscending() | True when the x values never decrease, as a time series’ do; a scatter filled in any order is not. |
public int nearestIndexOfX(double x) | The index whose x is closest to x among the points that have a y value, by binary search; only meaningful when isAscending(). |
public double animatedY(ChartContext ctx, int i) | The y shown at i in the current frame: the value interpolated from where the last transition started. |
protected boolean consumesStackBase() | True for a series drawn on its stack base (an area or a bar), which a stack group lifts and whose layer shrinks with the fraction it is shown while it fades; false for marks that keep their own values (scatter, error bars, candles, boxes). |
public double animatedAux(ChartContext ctx, int channel, int i) | Extra channel channel of point i as shown in the current frame. |
protected boolean isAuxRelative(int channel) | True when extra channel channel is a value on the y scale (a high, a low, a quartile) and so animates as an offset from the point’s value; false for a channel of its own scale, such as a bubble size, which animates by itself. |
public double animatedBase(ChartContext ctx, int i) | The stacked base shown at i in the current frame. |
protected double targetBase(int i) | The base point i settles on once the running transition ends: the stack of the earlier layers weighted by the fraction each ends at, or getBase(int) outside a stack group. |
protected boolean hasOwnBase() | True for a series whose base is its own data (a range bar’s start, a waterfall’s running total) rather than a stack: it is drawn from that base but is no layer of a stack. |
protected void captureTransitionStart() | Records the values currently on screen as the start of the next transition. |
protected void transitionEnded() | Called by the chart when a transition has finished, so a subclass can drop the start values it captured; a later change that forgot to snapshot then shows its new values instead of replaying a transition from long gone data. |
protected void captureEntryStart() | Records a zero baseline as the start of the entry animation. |
public double[] getXBounds() | The extent of the data along x, {min, max}, or null when empty or not cartesian. |
public double[] getXBoundsWithin(double maxX) | The extent along x of the data at or below maxX, {min, max}, or null when none is. |
public double[] getYBounds() | The extent of the data along y, {min, max}, or null when empty or not cartesian. |
public double getMinXSpacing() | The smallest gap between neighbouring x values, the width of one bar or candle slot; 1 when there are fewer than two points, which is a category band. |
protected int lowerBound(double x) | First index whose x is at or after x, for culling points outside the viewport. |
protected int[] visibleRange(ChartContext ctx) | The index range {from, to} (inclusive) worth painting: the visible points plus one neighbour each side so lines run to the plot edge. |
public int screenPosition(ChartContext ctx, int i, boolean vertical) | The screen position of point i along one direction, relative to the chart like ChartPoint.getScreenX(), without allocating a point. |
public int nearestScreenIndex(ChartContext ctx, int pos, boolean vertical) | The index of the point with a y value whose screen position along one direction is nearest pos, scanning every point; for data that is not ascending. |
public ChartPoint hitTest(ChartContext ctx, int x, int y, int radius) | Finds the data point nearest a screen position. |
public void collectTableRows(List<String[]> rows) | Adds this series’ data to an accessible table, one {series, item, value} row per point. |
protected String tableValue(int i) | The text of point i in the accessible data table. |
public int getPointCount() | The number of points along x, for a shared tooltip; -1 when not index aligned. |
public ChartPoint getPoint(ChartContext ctx, int index) | The point at index for a shared tooltip, or null. |
Inherited methods
From Series
getName, setName, getColor, setColor, isVisible, setVisible, isSecondaryAxis, setSecondaryAxis, isShowValues, setShowValues, getValueFormatter, setValueFormatter, getChart, paint, getSelectablePointCount, isPointCountFromLayout, paintLegendSymbol, getLegendEntryCount, getLegendEntryName, paintLegendEntrySymbol, isLegendEntryVisible, toggleLegendEntry, formatValue, formatTooltip, handleTap, attached, detached, repaintChart, getVisibilityFraction, isGap, lerp
Constructor details
XYSeries
protected XYSeries(String name)Parameters
nameString- the legend name
XYSeries
protected XYSeries(String name, int auxChannels)auxChannels extra values beside each y.Parameters
nameString- the series name
auxChannelsint- number of extra values per point
Method details
setRows
protected void setRows(double[] x, double[] y, double[][] channels)Parameters
xdouble[]- x values, or null for 0, 1, 2…
ydouble[]- the main values
channelsdouble[][]- one array per extra channel, each as long as
y
addRow
protected void addRow(double x, double y, double[] values)Parameters
xdouble- the x value
ydouble- the main value
valuesdouble[]- the extra values, one per channel
auxDefault
protected double auxDefault(int channel, double y)getAux
protected double getAux(int channel, int i)isCartesian
public boolean isCartesian()setData
public XYSeries setData(double[] x, double[] y)x may be null, in which case points are numbered 0, 1, 2 …
(the positions of a category axis).setValues
public XYSeries setValues(double... y)add
public XYSeries add(double y)add
public XYSeries add(double x, double y)setMaxPoints the oldest point drops off, for real time data.set
public XYSeries set(int index, double y)index.clear
public XYSeries clear()setMaxPoints
public XYSeries setMaxPoints(int n)n points, dropping the oldest as new ones arrive; 0 keeps all.setStackGroup
public XYSeries setStackGroup(String group)getStackGroup
public String getStackGroup()size
public int size()getX
public double getX(int i)i.getY
public double getY(int i)i.getBase
public double getBase(int i)i rests on: 0, or the stacked sum of the earlier series
in its group.dataChanged
protected void dataChanged()isGapAt
public boolean isGapAt(int i)i has no value to show: its x or its y is NaN or infinite.Parameters
iint- the point index
Returns
isAscending
public boolean isAscending()nearestIndexOfX
public int nearestIndexOfX(double x)x among the points that have a y value, by binary
search; only meaningful when isAscending().Parameters
xdouble- a data value on the x axis
Returns
animatedY
public double animatedY(ChartContext ctx, int i)i in the current frame: the value interpolated from where the last
transition started.consumesStackBase
protected boolean consumesStackBase()Returns
animatedAux
public double animatedAux(ChartContext ctx, int channel, int i)channel of point i as shown in the current frame. It moves with the
point’s animated value and, like it, from where the last transition started, matched by x;
so a change to one point leaves every other point still. A point with no earlier state
(the series’ entry) grows out of its own value.Parameters
ctxChartContext- the drawing context, or null for the settled value
channelint- the extra channel
iint- the point index
Returns
isAuxRelative
protected boolean isAuxRelative(int channel)channel is a value on the y scale (a high, a low, a quartile)
and so animates as an offset from the point’s value; false for a channel of its own
scale, such as a bubble size, which animates by itself.Parameters
channelint- the extra channel
Returns
animatedBase
public double animatedBase(ChartContext ctx, int i)i in the current frame.targetBase
protected double targetBase(int i)The base point i settles on once the running transition ends: the stack of the earlier
layers weighted by the fraction each ends at, or getBase(int) outside a stack group.
A series whose base is its own data (a range bar’s start, a waterfall’s running total)
overrides this to answer that, so the tween ends exactly where the settled value is.
i: the point index
Returns
hasOwnBase
protected boolean hasOwnBase()Returns
captureTransitionStart
protected void captureTransitionStart()transitionEnded
protected void transitionEnded()captureEntryStart
protected void captureEntryStart()getXBounds
public double[] getXBounds(){min, max}, or null when empty or not cartesian.getXBoundsWithin
public double[] getXBoundsWithin(double maxX)maxX, {min, max}, or null when none is.
A category axis with no labels asks for this to leave a far outlier out of its bands.Parameters
maxXdouble- the largest x that counts
Returns
getYBounds
public double[] getYBounds(){min, max}, or null when empty or not cartesian.getMinXSpacing
public double getMinXSpacing()lowerBound
protected int lowerBound(double x)x, for culling points outside the viewport.visibleRange
protected int[] visibleRange(ChartContext ctx)The index range {from, to} (inclusive) worth painting: the visible points plus one
neighbour each side so lines run to the plot edge. Data whose x values are not
ascending (a scatter filled in any order) cannot be binary searched, so every point is
in range then.
The array is reused by the next call on this series, so read it before calling again.
screenPosition
public int screenPosition(ChartContext ctx, int i, boolean vertical)i along one direction, relative to the chart like
ChartPoint.getScreenX(), without allocating a point.Parameters
ctxChartContext- the frame
iint- the point index
verticalboolean- true for the y coordinate, false for x
Returns
nearestScreenIndex
public int nearestScreenIndex(ChartContext ctx, int pos, boolean vertical)pos, scanning every point; for data that is not ascending. Allocates nothing,
as it runs on every pointer move.Parameters
ctxChartContext- the frame
posint- the pointer coordinate, relative to the chart
verticalboolean- true to compare y coordinates, false for x
Returns
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
collectTableRows
public void collectTableRows(List<String[]> rows){series, item, value} row per point.
Used by Chart.toTable() and the chart’s accessibility text.Parameters
rowsList<String[]>- the list to append rows to
tableValue
protected String tableValue(int i)i in the accessible data table.Parameters
iint- the point index
Returns
getPointCount
public int getPointCount()getPoint
public ChartPoint getPoint(ChartContext ctx, int index)index for a shared tooltip, or null.