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

public class WaterfallSeries

  1. Object
  2. Series
  3. XYSeries
  4. BarSeries
  5. WaterfallSeries

A waterfall (bridge) chart: each bar starts where the previous one ended, so a sequence of gains and losses reads as a running total. Total bars restart from zero and show the sum.

A total’s value is always computed: it is the sum of the steps before it that are still in the series, so set on a total bar is ignored, and once a setMaxPoints window slides the oldest steps out a total sums only the steps that remain (the bridge must stay joined to what is drawn). Which bars are totals is fixed by setSteps; setData keeps that marking by position (row i stays a total if it was one) and new rows are plain steps, so replacing the numbers of a bridge does not silently turn its totals into steps. To change the marking, call setSteps again. A point added by add is always a plain step.

new WaterfallSeries("Profit").setSteps(new double[]{120, -30, -25, 40, 0}, new boolean[]{false, false, false, false, true});

A waterfall

Constructors

public WaterfallSeries(String name)Creates an empty series.

Methods

public WaterfallSeries setSteps(double[] deltas, boolean[] isTotal)Replaces all steps.
public XYSeries setData(double[] x, double[] y)Replaces the deltas, keeping which rows are totals by position: row i stays a total when it was one, and rows past the old size are plain steps.
protected void dataChanged()Recomputes every base and total from the deltas, so set, add and a slide keep the bridge joined.
public WaterfallSeries setConnectors(boolean c)Shows or hides the thin lines joining each bar’s end to the next bar’s start.
public boolean isTotal(int i)True when bar i is a total.
protected double auxDefault(int channel, double y)A point added by add is a plain step, never a total.
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 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).
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 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.
public double[] getYBounds()The extent of the data along y, {min, max}, or null when empty or not cartesian.
protected int colorAt(ChartContext ctx, int i)The fill colour of bar i; the series colour unless a subclass colours bars by value.
public void paint(ChartContext ctx)Paints the series.
public String formatTooltip(ChartContext ctx, ChartPoint p)The tooltip row for a point: the series or point name and its formatted value.

Inherited methods

Constructor details

WaterfallSeries

public WaterfallSeries(String name)
Creates an empty series.

Parameters

name String
the series name

Method details

setSteps

public WaterfallSeries setSteps(double[] deltas, boolean[] isTotal)
Replaces all steps.

Parameters

deltas double[]
the change at each step; ignored for total bars
isTotal boolean[]
which bars show the running total instead of a change, or null for none

Returns

this series

setData

public XYSeries setData(double[] x, double[] y)
Replaces the deltas, keeping which rows are totals by position: row i stays a total when it was one, and rows past the old size are plain steps. Use setSteps to change the marking.

dataChanged

protected void dataChanged()
Recomputes every base and total from the deltas, so set, add and a slide keep the bridge joined. A NaN delta is a gap: its bar is not drawn and the running total carries past it.

setConnectors

public WaterfallSeries setConnectors(boolean c)
Shows or hides the thin lines joining each bar’s end to the next bar’s start.

Parameters

c boolean
true to draw connectors

Returns

this series

isTotal

public boolean isTotal(int i)
True when bar i is a total.

auxDefault

protected double auxDefault(int channel, double y)
A point added by add is a plain step, never a total.

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.

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

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

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

getYBounds

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

colorAt

protected int colorAt(ChartContext ctx, int i)
The fill colour of bar i; the series colour unless a subclass colours bars by value.

Parameters

ctx ChartContext
the paint context
i int
the bar index

Returns

an RGB colour

paint

public void paint(ChartContext ctx)
Paints the series.

Parameters

ctx ChartContext
the current frame: graphics, plot area, axes and animation progress

formatTooltip

public String formatTooltip(ChartContext ctx, ChartPoint p)
The tooltip row for a point: the series or point name and its formatted value. Series with several values per point (open/high/low/close, ranges, box plots) override this.

Parameters

ctx ChartContext
the last paint context
p ChartPoint
the point

Returns

one line of text