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

public abstract class XYSeries

  1. Object
  2. Series
  3. 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

Constructor details

XYSeries

protected XYSeries(String name)
Creates an empty series.

Parameters

name String
the legend name

XYSeries

protected XYSeries(String name, int auxChannels)
Creates a series that keeps auxChannels extra values beside each y.

Parameters

name String
the series name
auxChannels int
number of extra values per point

Method details

setRows

protected void setRows(double[] x, double[] y, double[][] channels)
Replaces all points, each with its extra values.

Parameters

x double[]
x values, or null for 0, 1, 2…
y double[]
the main values
channels double[][]
one array per extra channel, each as long as y

addRow

protected void addRow(double x, double y, double[] values)
Appends one point with its extra values, sliding the window when a maximum is set.

Parameters

x double
the x value
y double
the main value
values double[]
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()
True for series drawn against x and y axes; false for pies, treemaps and other series that fill the plot themselves.

setData

public XYSeries setData(double[] x, double[] y)
Replaces all data. 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)
Replaces all data with values at x = 0, 1, 2 …

add

public XYSeries add(double y)
Appends a point at the next index.

add

public XYSeries add(double x, double y)
Appends a point. With setMaxPoints the oldest point drops off, for real time data.

set

public XYSeries set(int index, double y)
Changes the value at index.

clear

public XYSeries clear()
Removes every point.

setMaxPoints

public XYSeries setMaxPoints(int n)
Keeps at most n points, dropping the oldest as new ones arrive; 0 keeps all.

setStackGroup

public XYSeries setStackGroup(String group)
Stacks this series on earlier ones sharing the same group name; null for none.

getStackGroup

public String getStackGroup()
The stack group, or null.

size

public int size()
The number of points.

getX

public double getX(int i)
The x value at i.

getY

public double getY(int i)
The y value at i.

getBase

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.

dataChanged

protected void dataChanged()
Tells the chart this series’ data changed, which animates the new values in.

isGapAt

public boolean isGapAt(int i)
True when point i has no value to show: its x or its y is NaN or infinite.

Parameters

i int
the point index

Returns

true for a gap

isAscending

public boolean isAscending()
True when the x values never decrease, as a time series’ do; a scatter filled in any order is not. Checked once per change to the data.

nearestIndexOfX

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().

Parameters

x double
a data value on the x axis

Returns

the nearest index, or -1 for an empty series

animatedY

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.

consumesStackBase

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).

Returns

false by default

animatedAux

public double animatedAux(ChartContext ctx, int channel, int i)
Extra channel 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

ctx ChartContext
the drawing context, or null for the settled value
channel int
the extra channel
i int
the point index

Returns

the channel value for this frame

isAuxRelative

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.

Parameters

channel int
the extra channel

Returns

true by default

animatedBase

public double animatedBase(ChartContext ctx, int i)
The stacked base shown at 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

the settled base

hasOwnBase

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.

Returns

false by default

captureTransitionStart

protected void captureTransitionStart()
Records the values currently on screen as the start of the next transition. Called by the chart before data changes; a subclass with animated data overrides it.

transitionEnded

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.

captureEntryStart

protected void captureEntryStart()
Records a zero baseline as the start of the entry animation.

getXBounds

public double[] getXBounds()
The extent of the data along x, {min, max}, or null when empty or not cartesian.

getXBoundsWithin

public double[] getXBoundsWithin(double maxX)
The extent along x of the data at or below 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

maxX double
the largest x that counts

Returns

the bounds of the points that count, or null

getYBounds

public double[] getYBounds()
The extent of the data along y, {min, max}, or null when empty or not cartesian.

getMinXSpacing

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.

lowerBound

protected int lowerBound(double x)
First index whose x is at or after 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)
The screen position of point i along one direction, relative to the chart like ChartPoint.getScreenX(), without allocating a point.

Parameters

ctx ChartContext
the frame
i int
the point index
vertical boolean
true for the y coordinate, false for x

Returns

the coordinate in pixels

nearestScreenIndex

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. Allocates nothing, as it runs on every pointer move.

Parameters

ctx ChartContext
the frame
pos int
the pointer coordinate, relative to the chart
vertical boolean
true to compare y coordinates, false for x

Returns

the index, or -1 when no point has a value

hitTest

public ChartPoint hitTest(ChartContext ctx, int x, int y, int radius)
Finds the data point nearest a screen position.

Parameters

ctx ChartContext
the frame the series was last painted in
x int
chart relative x
y int
chart relative y
radius int
how far from the point a touch may land and still hit it

Returns

the point, or null

collectTableRows

public void collectTableRows(List<String[]> rows)
Adds this series’ data to an accessible table, one {series, item, value} row per point. Used by Chart.toTable() and the chart’s accessibility text.

Parameters

rows List<String[]>
the list to append rows to

tableValue

protected String tableValue(int i)
The text of point i in the accessible data table.

Parameters

i int
the point index

Returns

the formatted value

getPointCount

public int getPointCount()
The number of points along x, for a shared tooltip; -1 when not index aligned.

getPoint

public ChartPoint getPoint(ChartContext ctx, int index)
The point at index for a shared tooltip, or null.