Class XYSeries

java.lang.Object
com.codename1.ui.chart.Series
com.codename1.ui.chart.series.XYSeries
Direct Known Subclasses:
BarSeries, BoxPlotSeries, CandlestickSeries, ErrorBarSeries, LineSeries, ScatterSeries

public abstract class XYSeries extends Series

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
    Modifier
    Constructor
    Description
    protected
    Creates an empty series.
    protected
    XYSeries(String name, int auxChannels)
    Creates a series that keeps auxChannels extra values beside each y.
  • Method Summary

    Modifier and Type
    Method
    Description
    add(double y)
    Appends a point at the next index.
    add(double x, double y)
    Appends a point.
    protected void
    addRow(double x, double y, double[] values)
    Appends one point with its extra values, sliding the window when a maximum is set.
    double
    animatedAux(ChartContext ctx, int channel, int i)
    Extra channel channel of point i as shown in the current frame.
    double
    The stacked base shown at i in the current frame.
    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 double
    auxDefault(int channel, double y)
     
    protected void
    Records a zero baseline as the start of the entry animation.
    protected void
    Records the values currently on screen as the start of the next transition.
    Removes every point.
    void
    Adds this series' data to an accessible table, one {series, item, value} row per point.
    protected boolean
    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).
    protected void
    Tells the chart this series' data changed, which animates the new values in.
    protected double
    getAux(int channel, int i)
     
    double
    getBase(int i)
    The base this series' point i rests on: 0, or the stacked sum of the earlier series in its group.
    double
    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.
    getPoint(ChartContext ctx, int index)
    The point at index for a shared tooltip, or null.
    int
    The number of points along x, for a shared tooltip; -1 when not index aligned.
    The stack group, or null.
    double
    getX(int i)
    The x value at i.
    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 below maxX, {min, max}, or null when none is.
    double
    getY(int i)
    The y value at i.
    double[]
    The extent of the data along y, {min, max}, or null when empty or not cartesian.
    protected boolean
    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.
    hitTest(ChartContext ctx, int x, int y, int radius)
    Finds the data point nearest a screen position.
    boolean
    True when the x values never decrease, as a time series' do; a scatter filled in any order is not.
    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.
    boolean
    True for series drawn against x and y axes; false for pies, treemaps and other series that fill the plot themselves.
    boolean
    isGapAt(int i)
    True when point i has no value to show: its x or its y is NaN or infinite.
    protected int
    lowerBound(double x)
    First index whose x is at or after x, for culling points outside the viewport.
    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().
    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.
    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.
    set(int index, double y)
    Changes the value at index.
    setData(double[] x, double[] y)
    Replaces all data.
    setMaxPoints(int n)
    Keeps at most n points, dropping the oldest as new ones arrive; 0 keeps all.
    protected void
    setRows(double[] x, double[] y, double[][] channels)
    Replaces all points, each with its extra values.
    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 ...
    int
    The number of points.
    protected String
    tableValue(int i)
    The text of point i in the accessible data table.
    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 void
    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 int[]
    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 Object

    clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
  • Constructor Details

    • XYSeries

      protected XYSeries(String name)

      Creates an empty series.

      Parameters
      • name: the legend name
    • XYSeries

      protected XYSeries(String name, int auxChannels)

      Creates a series that keeps auxChannels extra 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 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: 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: Series
      True for series drawn against x and y axes; false for pies, treemaps and other series that fill the plot themselves.
      Specified by:
      isCartesian in class Series
    • 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()
      Description copied from class: Series
      Tells the chart this series' data changed, which animates the new values in.
      Overrides:
      dataChanged in class Series
    • 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: 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: 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: 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 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: 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()
      Description copied from class: Series
      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.
      Overrides:
      captureTransitionStart in class Series
    • transitionEnded

      protected void transitionEnded()
      Description copied from class: Series
      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.
      Overrides:
      transitionEnded in class Series
    • captureEntryStart

      protected void captureEntryStart()
      Description copied from class: Series
      Records a zero baseline as the start of the entry animation.
      Overrides:
      captureEntryStart in class Series
    • getXBounds

      public double[] getXBounds()
      Description copied from class: Series
      The extent of the data along x, {min, max}, or null when empty or not cartesian.
      Overrides:
      getXBounds in class Series
    • getXBoundsWithin

      public double[] getXBoundsWithin(double maxX)
      Description copied from class: Series

      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: the largest x that counts
      Returns

      the bounds of the points that count, or null

      Overrides:
      getXBoundsWithin in class Series
    • getYBounds

      public double[] getYBounds()
      Description copied from class: Series
      The extent of the data along y, {min, max}, or null when empty or not cartesian.
      Overrides:
      getYBounds in class Series
    • 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: the frame

      • i: the point index

      • vertical: 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: 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

      public ChartPoint hitTest(ChartContext ctx, int x, int y, int radius)
      Description copied from class: Series

      Finds 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

      Overrides:
      hitTest in class Series
    • collectTableRows

      public void collectTableRows(List<String[]> rows)
      Description copied from class: Series

      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: the list to append rows to
      Overrides:
      collectTableRows in class Series
    • tableValue

      protected String tableValue(int i)

      The text of point i in the accessible data table.

      Parameters
      • i: the point index
      Returns

      the formatted value

    • getPointCount

      public int getPointCount()
      Description copied from class: Series
      The number of points along x, for a shared tooltip; -1 when not index aligned.
      Overrides:
      getPointCount in class Series
    • getPoint

      public ChartPoint getPoint(ChartContext ctx, int index)
      Description copied from class: Series
      The point at index for a shared tooltip, or null.
      Overrides:
      getPoint in class Series