Class Series

java.lang.Object
com.codename1.ui.chart.Series
Direct Known Subclasses:
CategoricalSeries, GaugeSeries, HeatmapSeries, HierarchySeries, RadarSeries, SankeySeries, XYSeries

public abstract class Series extends Object

One data series. A series owns its data, its colour and how it paints itself; there is no separate renderer object to keep in step with it.

Changing data through a series' own methods animates the chart from the old values to the new ones. Batch several changes inside Chart.update(Runnable) to animate them as one transition.

  • Constructor Summary

    Constructors
    Modifier
    Constructor
    Description
    protected
    Series(String name)
    Creates a named series.
  • Method Summary

    Modifier and Type
    Method
    Description
    protected void
    Called by the chart when this series is added to it, and again when the chart comes back on screen (its initComponent); a series may be told more than once.
    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.
    void
    Adds this series' data to an accessible table, one {series, item, value} row per point.
    protected void
    Tells the chart this series' data changed, which animates the new values in.
    protected void
    Called by the chart when this series is removed from it, or the chart leaves the screen (its deinitialize); a series may be told more than once.
    The tooltip row for a point: the series or point name and its formatted value.
    formatValue(ChartContext ctx, double value)
    Formats a value for a label or tooltip.
    The chart this series is in, or null.
    int
    The explicit colour, or the theme colour for this series' position.
    int
    Entries this series contributes to the legend; a single series by default, one per slice for a pie.
    The name of legend entry i.
    The legend name.
    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.
    int
    The number of points Chart.setSelection and arrow-key stepping can reach by index.
    Formatter for value labels and the tooltip, or null to use the value axis'.
    protected float
    The current shown fraction, 0 hidden to 1 shown, animated while the user toggles it.
    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[]
    The extent of the data along y, {min, max}, or null when empty or not cartesian.
    boolean
    Called when a point of this series is tapped, before the chart selects it.
    hitTest(ChartContext ctx, int x, int y, int radius)
    Finds the data point nearest a screen position.
    abstract boolean
    True for series drawn against x and y axes; false for pies, treemaps and other series that fill the plot themselves.
    protected static boolean
    isGap(double v)
    True for a value that cannot be plotted: NaN or either infinity.
    boolean
    True if entry i is visible; a pie slice can be hidden on its own.
    protected boolean
    True when getPointCount() counts points a paint laid out (treemap, sunburst, Sankey) rather than the model's points, so an index past it may exist after the next paint.
    boolean
    True when the series is measured against the right hand value axis.
    boolean
    True when value labels are drawn next to the data.
    boolean
    False while the user has hidden it from the legend or the app hid it.
    protected static double
    lerp(double a, double b, double t)
    Interpolates for transitions; a start that is a gap (NaN or infinite) means the value appears without a tween, since every in-between value of an infinite start is NaN or infinite and the point would vanish for the whole transition.
    abstract void
    Paints the series.
    void
    paintLegendEntrySymbol(Graphics g, int i, int x, int y, int size)
    Paints the swatch of legend entry i.
    void
    paintLegendSymbol(Graphics g, int x, int y, int size)
    Paints the legend swatch.
    protected void
    Repaints without a transition.
    setColor(int rgb)
    Fixes the series colour instead of taking it from the theme palette.
    Renames the series.
    setSecondaryAxis(boolean secondaryAxis)
    Plots the series against the secondary (right) value axis.
    setShowValues(boolean showValues)
    Draws value labels on the data.
    Sets how values print in labels and tooltips.
    setVisible(boolean visible)
    Shows or hides the series with an animated transition.
    void
    Toggles legend entry i.
    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.

    Methods inherited from class Object

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

    • Series

      protected Series(String name)

      Creates a named series.

      Parameters
      • name: shown in the legend and the tooltip
  • Method Details

    • getName

      public String getName()
      The legend name.
    • setName

      public Series setName(String name)
      Renames the series.
    • getColor

      public int getColor()
      The explicit colour, or the theme colour for this series' position.
    • setColor

      public Series setColor(int rgb)
      Fixes the series colour instead of taking it from the theme palette.
    • isVisible

      public boolean isVisible()
      False while the user has hidden it from the legend or the app hid it.
    • setVisible

      public Series setVisible(boolean visible)
      Shows or hides the series with an animated transition.
    • isSecondaryAxis

      public boolean isSecondaryAxis()
      True when the series is measured against the right hand value axis.
    • setSecondaryAxis

      public Series setSecondaryAxis(boolean secondaryAxis)
      Plots the series against the secondary (right) value axis.
    • isShowValues

      public boolean isShowValues()
      True when value labels are drawn next to the data. Labels that would collide are left out rather than drawn over each other.
    • setShowValues

      public Series setShowValues(boolean showValues)
      Draws value labels on the data.
    • getValueFormatter

      public ValueFormatter getValueFormatter()
      Formatter for value labels and the tooltip, or null to use the value axis'.
    • setValueFormatter

      public Series setValueFormatter(ValueFormatter valueFormatter)
      Sets how values print in labels and tooltips.
    • getChart

      public Chart getChart()
      The chart this series is in, or null.
    • isCartesian

      public abstract boolean isCartesian()
      True for series drawn against x and y axes; false for pies, treemaps and other series that fill the plot themselves.
    • getXBounds

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

      public double[] getXBoundsWithin(double maxX)

      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

    • getYBounds

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

      public abstract void paint(ChartContext ctx)

      Paints the series.

      Parameters
      • ctx: the current frame: graphics, plot area, axes and animation progress
    • hitTest

      public ChartPoint hitTest(ChartContext ctx, int x, int y, int radius)

      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

    • getPointCount

      public int getPointCount()
      The number of points along x, for a shared tooltip; -1 when not index aligned.
    • getSelectablePointCount

      public int getSelectablePointCount()
      The number of points Chart.setSelection and arrow-key stepping can reach by index. The same as getPointCount(), except for a series whose points are not index aligned with other series (scatter), which still has its own points to select.
    • isPointCountFromLayout

      protected boolean isPointCountFromLayout()
      True when getPointCount() counts points a paint laid out (treemap, sunburst, Sankey) rather than the model's points, so an index past it may exist after the next paint.
    • getPoint

      public ChartPoint getPoint(ChartContext ctx, int index)
      The point at index for a shared tooltip, or null.
    • paintLegendSymbol

      public void paintLegendSymbol(Graphics g, int x, int y, int size)

      Paints the legend swatch.

      Parameters
      • g: graphics

      • x: swatch left

      • y: swatch top

      • size: swatch size

    • getLegendEntryCount

      public int getLegendEntryCount()
      Entries this series contributes to the legend; a single series by default, one per slice for a pie.
    • getLegendEntryName

      public String getLegendEntryName(int i)
      The name of legend entry i.
    • paintLegendEntrySymbol

      public void paintLegendEntrySymbol(Graphics g, int i, int x, int y, int size)
      Paints the swatch of legend entry i.
    • isLegendEntryVisible

      public boolean isLegendEntryVisible(int i)
      True if entry i is visible; a pie slice can be hidden on its own.
    • toggleLegendEntry

      public void toggleLegendEntry(int i)
      Toggles legend entry i.
    • captureTransitionStart

      protected void captureTransitionStart()
      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.
    • captureEntryStart

      protected void captureEntryStart()
      Records a zero baseline as the start of the entry animation.
    • transitionEnded

      protected void transitionEnded()
      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.
    • formatValue

      public String formatValue(ChartContext ctx, double value)
      Formats a value for a label or tooltip.
    • 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: the last paint context

      • p: the point

      Returns

      one line of text

    • collectTableRows

      public void collectTableRows(List<String[]> rows)

      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
    • handleTap

      public boolean handleTap(ChartPoint p)

      Called when a point of this series is tapped, before the chart selects it. A series that navigates on tap (drilling into a treemap node) returns true to stop the selection.

      Parameters
      • p: the tapped point
      Returns

      true if the tap was consumed

    • attached

      protected void attached()
      Called by the chart when this series is added to it, and again when the chart comes back on screen (its initComponent); a series may be told more than once. A series that listens to a model outliving it (a TreeNode tree) registers here, so the model does not keep a discarded chart reachable: a chart taken off screen, or a series removed from its chart, stops listening.
    • detached

      protected void detached()
      Called by the chart when this series is removed from it, or the chart leaves the screen (its deinitialize); a series may be told more than once. Undoes attached().
    • dataChanged

      protected void dataChanged()
      Tells the chart this series' data changed, which animates the new values in.
    • repaintChart

      protected void repaintChart()
      Repaints without a transition.
    • getVisibilityFraction

      protected float getVisibilityFraction()
      The current shown fraction, 0 hidden to 1 shown, animated while the user toggles it.
    • isGap

      protected static boolean isGap(double v)
      True for a value that cannot be plotted: NaN or either infinity. Such a point is a gap, drawn as nothing and kept out of every axis bound.
    • lerp

      protected static double lerp(double a, double b, double t)
      Interpolates for transitions; a start that is a gap (NaN or infinite) means the value appears without a tween, since every in-between value of an infinite start is NaN or infinite and the point would vanish for the whole transition.