Class XYSeries
- Direct Known Subclasses:
BarSeries, 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.
-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionadd(double y) Appends a point at the next index.add(double x, double y) Appends a point.protected voidaddRow(double x, double y, double[] values) Appends one point with its extra values, sliding the window when a maximum is set.doubleanimatedAux(ChartContext ctx, int channel, int i) Extra channelchannelof pointias shown in the current frame.doubleanimatedBase(ChartContext ctx, int i) The stacked base shown atiin the current frame.doubleanimatedY(ChartContext ctx, int i) The y shown atiin the current frame: the value interpolated from where the last transition started.protected doubleauxDefault(int channel, double y) protected voidRecords a zero baseline as the start of the entry animation.protected voidRecords the values currently on screen as the start of the next transition.clear()Removes every point.voidcollectTableRows(List<String[]> rows) Adds this series' data to an accessible table, one{series, item, value}row per point.protected booleanTrue 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).protected voidTells the chart this series' data changed, which animates the new values in.protected doublegetAux(int channel, int i) doublegetBase(int i) The base this series' pointirests on: 0, or the stacked sum of the earlier series in its group.doubleThe 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.getPoint(ChartContext ctx, int index) The point atindexfor a shared tooltip, or null.intThe number of points along x, for a shared tooltip; -1 when not index aligned.The stack group, or null.doublegetX(int i) The x value ati.double[]The extent of the data along x,{min, max}, or null when empty or not cartesian.double[]getXBoundsWithin(double maxX) The extent along x of the data at or belowmaxX,{min, max}, or null when none is.doublegetY(int i) The y value ati.double[]The extent of the data along y,{min, max}, or null when empty or not cartesian.protected booleanTrue 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.hitTest(ChartContext ctx, int x, int y, int radius) Finds the data point nearest a screen position.booleanTrue when the x values never decrease, as a time series' do; a scatter filled in any order is not.protected booleanisAuxRelative(int channel) True when extra channelchannelis 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.booleanTrue for series drawn against x and y axes; false for pies, treemaps and other series that fill the plot themselves.booleanisGapAt(int i) True when pointihas no value to show: its x or its y is NaN or infinite.protected intlowerBound(double x) First index whose x is at or afterx, for culling points outside the viewport.intnearestIndexOfX(double x) The index whose x is closest toxamong the points that have a y value, by binary search; only meaningful whenisAscending().intnearestScreenIndex(ChartContext ctx, int pos, boolean vertical) The index of the point with a y value whose screen position along one direction is nearestpos, scanning every point; for data that is not ascending.intscreenPosition(ChartContext ctx, int i, boolean vertical) The screen position of pointialong one direction, relative to the chart likeChartPoint.getScreenX(), without allocating a point.set(int index, double y) Changes the value atindex.setData(double[] x, double[] y) Replaces all data.setMaxPoints(int n) Keeps at mostnpoints, dropping the oldest as new ones arrive; 0 keeps all.protected voidsetRows(double[] x, double[] y, double[][] channels) Replaces all points, each with its extra values.setStackGroup(String group) Stacks this series on earlier ones sharing the same group name; null for none.setValues(double... y) Replaces all data with values at x = 0, 1, 2 ...intsize()The number of points.protected StringtableValue(int i) The text of pointiin the accessible data table.protected doubletargetBase(int i) The base pointisettles on once the running transition ends: the stack of the earlier layers weighted by the fraction each ends at, orgetBase(int)outside a stack group.protected voidCalled 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 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.Methods inherited from class Series
attached, detached, formatTooltip, formatValue, getChart, getColor, getLegendEntryCount, getLegendEntryName, getName, getSelectablePointCount, getValueFormatter, getVisibilityFraction, handleTap, isGap, isLegendEntryVisible, isPointCountFromLayout, isSecondaryAxis, isShowValues, isVisible, lerp, paint, paintLegendEntrySymbol, paintLegendSymbol, repaintChart, setColor, setName, setSecondaryAxis, setShowValues, setValueFormatter, setVisible, toggleLegendEntry
-
Constructor Details
-
XYSeries
Creates an empty series.
Parameters
name: the legend name
-
XYSeries
Creates a series that keeps
auxChannelsextra values beside each y.Parameters
-
name: the series name -
auxChannels: 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: x values, or null for 0, 1, 2... -
y: the main values -
channels: one array per extra channel, each as long asy
-
-
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: the x value -
y: the main value -
values: 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()Description copied from class:SeriesTrue for series drawn against x and y axes; false for pies, treemaps and other series that fill the plot themselves.- Specified by:
isCartesianin classSeries
-
setData
Replaces all data.xmay be null, in which case points are numbered 0, 1, 2 ... (the positions of a category axis). -
setValues
Replaces all data with values at x = 0, 1, 2 ... -
add
Appends a point at the next index. -
add
Appends a point. WithsetMaxPointsthe oldest point drops off, for real time data. -
set
Changes the value atindex. -
clear
Removes every point. -
setMaxPoints
Keeps at mostnpoints, dropping the oldest as new ones arrive; 0 keeps all. -
setStackGroup
-
getStackGroup
The stack group, or null. -
size
public int size()The number of points. -
getX
public double getX(int i) The x value ati. -
getY
public double getY(int i) The y value ati. -
getBase
public double getBase(int i) The base this series' pointirests on: 0, or the stacked sum of the earlier series in its group. -
dataChanged
protected void dataChanged()Description copied from class:SeriesTells the chart this series' data changed, which animates the new values in.- Overrides:
dataChangedin classSeries
-
isGapAt
public boolean isGapAt(int i) True when point
ihas no value to show: its x or its y is NaN or infinite.Parameters
i: 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
xamong the points that have a y value, by binary search; only meaningful whenisAscending().Parameters
x: a data value on the x axis
Returns
the nearest index, or -1 for an empty series
-
animatedY
The y shown atiin 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
Extra channel
channelof pointias 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: the drawing context, or null for the settled value -
channel: the extra channel -
i: the point index
Returns
the channel value for this frame
-
-
isAuxRelative
protected boolean isAuxRelative(int channel) True when extra channel
channelis 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: the extra channel
Returns
true by default
-
animatedBase
The stacked base shown atiin the current frame. -
targetBase
protected double targetBase(int i) The base point
isettles on once the running transition ends: the stack of the earlier layers weighted by the fraction each ends at, orgetBase(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()Description copied from class:SeriesRecords 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.- Overrides:
captureTransitionStartin classSeries
-
transitionEnded
protected void transitionEnded()Description copied from class:SeriesCalled 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.- Overrides:
transitionEndedin classSeries
-
captureEntryStart
protected void captureEntryStart()Description copied from class:SeriesRecords a zero baseline as the start of the entry animation.- Overrides:
captureEntryStartin classSeries
-
getXBounds
public double[] getXBounds()Description copied from class:SeriesThe extent of the data along x,{min, max}, or null when empty or not cartesian.- Overrides:
getXBoundsin classSeries
-
getXBoundsWithin
public double[] getXBoundsWithin(double maxX) Description copied from class:SeriesThe 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: the largest x that counts
Returns
the bounds of the points that count, or null
- Overrides:
getXBoundsWithinin classSeries
-
getYBounds
public double[] getYBounds()Description copied from class:SeriesThe extent of the data along y,{min, max}, or null when empty or not cartesian.- Overrides:
getYBoundsin classSeries
-
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 afterx, for culling points outside the viewport. -
visibleRange
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
The screen position of point
ialong one direction, relative to the chart likeChartPoint.getScreenX(), without allocating a point.Parameters
-
ctx: the frame -
i: the point index -
vertical: true for the y coordinate, false for x
Returns
the coordinate in pixels
-
-
nearestScreenIndex
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: the frame -
pos: the pointer coordinate, relative to the chart -
vertical: true to compare y coordinates, false for x
Returns
the index, or -1 when no point has a value
-
-
hitTest
Description copied from class:SeriesFinds the data point nearest a screen position.
Parameters
-
ctx: the frame the series was last painted in -
x: chart relative x -
y: chart relative y -
radius: how far from the point a touch may land and still hit it
Returns
the point, or null
-
-
collectTableRows
Description copied from class:SeriesAdds this series' data to an accessible table, one
{series, item, value}row per point. Used byChart.toTable()and the chart's accessibility text.Parameters
rows: the list to append rows to
- Overrides:
collectTableRowsin classSeries
-
tableValue
The text of point
iin the accessible data table.Parameters
i: the point index
Returns
the formatted value
-
getPointCount
public int getPointCount()Description copied from class:SeriesThe number of points along x, for a shared tooltip; -1 when not index aligned.- Overrides:
getPointCountin classSeries
-
getPoint
Description copied from class:SeriesThe point atindexfor a shared tooltip, or null.
-