Class LineChart


public class LineChart extends CartesianChart
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()
  • 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
    • 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
    • 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
    • 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