Class WaterfallSeries


public class WaterfallSeries extends BarSeries

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

  • Constructor Details

    • WaterfallSeries

      public WaterfallSeries(String name)

      Creates an empty series.

      Parameters
      • name: the series name
  • Method Details

    • setSteps

      public WaterfallSeries setSteps(double[] deltas, boolean[] isTotal)

      Replaces all steps.

      Parameters
      • deltas: the change at each step; ignored for total bars

      • isTotal: 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.
      Overrides:
      setData in class XYSeries
    • 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.
      Overrides:
      dataChanged in class XYSeries
    • 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: 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.
      Overrides:
      auxDefault in class XYSeries
    • getBase

      public double getBase(int i)
      Description copied from class: XYSeries
      The base this series' point i rests on: 0, or the stacked sum of the earlier series in its group.
      Overrides:
      getBase in class XYSeries
    • consumesStackBase

      protected boolean consumesStackBase()
      Description copied from class: XYSeries

      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

      Overrides:
      consumesStackBase in class BarSeries
    • hasOwnBase

      protected boolean hasOwnBase()
      Description copied from class: XYSeries

      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

      Overrides:
      hasOwnBase in class XYSeries
    • targetBase

      protected double targetBase(int i)
      Description copied from class: XYSeries

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

      Overrides:
      targetBase in class XYSeries
    • 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 BarSeries
    • colorAt

      protected int colorAt(ChartContext ctx, int i)
      Description copied from class: BarSeries

      The fill colour of bar i; the series colour unless a subclass colours bars by value.

      Parameters
      • ctx: the paint context

      • i: the bar index

      Returns

      an RGB colour

      Overrides:
      colorAt in class BarSeries
    • paint

      public void paint(ChartContext ctx)
      Description copied from class: Series

      Paints the series.

      Parameters
      • ctx: the current frame: graphics, plot area, axes and animation progress
      Overrides:
      paint in class BarSeries
    • formatTooltip

      public String formatTooltip(ChartContext ctx, ChartPoint p)
      Description copied from class: Series

      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: the last paint context

      • p: the point

      Returns

      one line of text

      Overrides:
      formatTooltip in class Series