Class LineChart


public final class LineChart extends CartesianChart<LineChart>
Lines, with optional filled areas and markers.

Everything about how a line looks belongs to its ChartSeries (width, marker size, whether it is filled, whether it curves), because a chart normally mixes them: a filled band for the range and a plain line for the actual. The chart-level setters here write through to every series, present and future, as a shorthand for "all of them".

Double.NaN breaks the line. A gap is drawn as a gap, and a filled series fills each run of real values separately rather than bridging the hole with a shape that asserts data nobody has.

Unlike bars, the value axis does not begin at zero: a line encodes value as position rather than as length, so it may zoom into the range that matters. chart.valueAxis().setBeginAtZero(true) restores the zero baseline.


 LineChart chart = new LineChart();
 chart.setLabels("00", "04", "08", "12", "16", "20");
 chart.addSeries(ChartSeries.of("Latency", 24, 21, 38, 42, 31, 26).setFilled(true));
 chart.setSmooth(true);
 
  • Constructor Details

    • LineChart

      public LineChart()
      An empty line chart: add labels and series before it has anything to draw.
  • Method Details

    • of

      public static LineChart of(List<String> labels, ChartSeries... series)
      A line chart over labels, with the given series.
    • setSmooth

      public LineChart setSmooth(boolean value)
      Curves every series, and every series added later. See ChartSeries.setSmooth(boolean).
    • setArea

      public LineChart setArea(boolean value)
      Fills every series, and every series added later. See ChartSeries.setFilled(boolean).
    • setLineWidth

      public LineChart setLineWidth(float points)
      Sets the stroke width of every series, and of every series added later.
    • setPointRadius

      public LineChart setPointRadius(float points)
      Sets the marker radius of every series, and of every series added later (0 hides).
    • tension

      public float tension()
      How hard a smoothed line curves.
    • setTension

      public LineChart setTension(float value)
      Sets the curve strength of smoothed series, from 0 (straight segments) to about 0.5 (a Catmull-Rom spline through the points). Default 0.4. Higher values overshoot past the data.
    • onSeriesAdded

      protected void onSeriesAdded(ChartSeries added)
      Description copied from class: Chart
      Called with a series that has just joined the chart, before anything is animated. Charts with per-series defaults of their own apply them here, so a series added after the default was set is styled like the ones that were already there.
      Overrides:
      onSeriesAdded in class Chart<LineChart>
    • paintMarks

      protected void paintMarks(Canvas canvas)
      Description copied from class: CartesianChart
      Paints the marks inside the plot region; grid and axes are already down.
      Specified by:
      paintMarks in class CartesianChart<LineChart>
    • hoverMarkMargin

      protected float hoverMarkMargin()
      A lit marker grows to HOVER_SCALE of its radius and is centred on the band, so it reaches that far outside it; the ring around it adds a border.
      Overrides:
      hoverMarkMargin in class CartesianChart<LineChart>
      Returns:
      a margin in logical points
    • pickSeries

      protected int pickSeries(int category, float localX, float localY)
      Description copied from class: CartesianChart
      Which series a pointer inside category is reporting: the mark it is on if any, and otherwise the nearest one, so a click in the whitespace of a column still names a datum. -1 when the category has nothing visible in it.
      Specified by:
      pickSeries in class CartesianChart<LineChart>
    • pointOf

      protected ChartPoint pointOf(int seriesIndex, int category)
      Description copied from class: CartesianChart
      The datum for one series at one category, anchored at that series' mark.
      Specified by:
      pointOf in class CartesianChart<LineChart>
    • onAccessibility

      protected void onAccessibility(Accessibility a)
      One chart node, named by the title when there is one and carrying which way the value axis runs, with one toggleable series node per series in paint order: the body every chart with axes shares, declared here because the coverage ratchet counts a hook the class declares itself.

      Every series is a node because every series is drawn, legend or no legend. A series' box is its legend row, the rectangle a click toggles it on and the one per-series geometry that stands still: the line's own points live in buffers that hold one series at a time, are overwritten by the next series painted, and are keyed on the animation's progress, so a box over them would be an alias that moved on every frame of an entry nobody is touching. A series with no legend row keeps the chart's box. The toggle is the model's visibility bit and never the fade a hidden line goes out through, so those frames damage the chart and publish nothing; smoothing, filling, the stroke width, the marker radius and the tension are style, and are nowhere in the tree. Nothing is generated from the axes or the values.

      Overrides:
      onAccessibility in class Widget<LineChart>
      Parameters:
      a - the node being described; write into it, and never keep it
    • onSyntheticAction

      protected boolean onSyntheticAction(long key, Accessible.Action action, Accessible.Argument arg)
      A toggle on a series node reaches the same path a click on its legend entry reaches, so a reader's toggle and a pointer's are one and the same to the chart and to the application, which is told nothing by either; refused when the legend is not interactive, when the series has no legend row for a pointer to have found, or when the key names no series.
      Overrides:
      onSyntheticAction in class Widget<LineChart>
      Parameters:
      key - the key this widget gave that child when it declared it
      action - what was asked
      arg - the argument, or Accessible.Argument.NONE
      Returns:
      whether this widget did it