Client API. The Codename One framework your app is built on: this runs on the device, not in a backend.
public class 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});
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
From XYSeries
setRows, addRow, getAux, isCartesian, setValues, add, add, set, clear, setMaxPoints, setStackGroup, getStackGroup, size, getX, getY, isGapAt, isAscending, nearestIndexOfX, animatedY, animatedAux, isAuxRelative, animatedBase, captureTransitionStart, transitionEnded, captureEntryStart, getXBoundsWithin, getMinXSpacing, lowerBound, visibleRange, screenPosition, nearestScreenIndex, collectTableRows, tableValue, getPointCount, getPoint
From Series
getName, setName, getColor, setColor, isVisible, setVisible, isSecondaryAxis, setSecondaryAxis, isShowValues, setShowValues, getValueFormatter, setValueFormatter, getChart, getSelectablePointCount, isPointCountFromLayout, paintLegendSymbol, getLegendEntryCount, getLegendEntryName, paintLegendEntrySymbol, isLegendEntryVisible, toggleLegendEntry, formatValue, handleTap, attached, detached, repaintChart, getVisibilityFraction, isGap, lerp
Constructor details
WaterfallSeries
public WaterfallSeries(String name)Parameters
nameString- the series name
Method details
setSteps
public WaterfallSeries setSteps(double[] deltas, boolean[] isTotal)Parameters
deltasdouble[]- the change at each step; ignored for total bars
isTotalboolean[]- which bars show the running total instead of a change, or null for none
Returns
setData
public XYSeries setData(double[] x, double[] y)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()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)Parameters
cboolean- true to draw connectors
Returns
isTotal
public boolean isTotal(int i)i is a total.auxDefault
protected double auxDefault(int channel, double y)add is a plain step, never a total.getBase
public double getBase(int i)i rests on: 0, or the stacked sum of the earlier series
in its group.consumesStackBase
protected boolean consumesStackBase()Returns
hasOwnBase
protected boolean hasOwnBase()Returns
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
getYBounds
public double[] getYBounds(){min, max}, or null when empty or not cartesian.colorAt
protected int colorAt(ChartContext ctx, int i)i; the series colour unless a subclass colours bars by value.Parameters
ctxChartContext- the paint context
iint- the bar index
Returns
paint
public void paint(ChartContext ctx)Parameters
ctxChartContext- the current frame: graphics, plot area, axes and animation progress
formatTooltip
public String formatTooltip(ChartContext ctx, ChartPoint p)Parameters
ctxChartContext- the last paint context
pChartPoint- the point