Class AreaGraph


  • public class AreaGraph
    extends AbstractLineGraph

    Plot a Line graph that has the area below the line filled in. Usually used to show individual components of a curve - for example, if you were graphing Overall Fruit Consumption over time, you could use an AreaGraph to break this down into different types of fruit. Because the area below the line is filled in, this type of graph is generally only used to show cumulative data.

    Here's a contrived example, which if nothing else shows how AreaGraphs are used to show accumulation. The values in the curves will be totalled automatically (unless we had set the Cumulative option

        import org.faceless.graph.*;
        import org.faceless.graph.math.*;
    
        // Create a "curve", showing the numbers from 1 to 5
        //
        DataCurve c = new DataCurve();
        c.set(1,1);
        c.set(2,2);
        c.set(3,3);
        c.set(4,4);
        c.set(5,5);
    
        AreaGraph g = new AreaGraph();
        g.addCurve("First Number", c);
        g.addCurve("Second Number", c);     // use the same curve twice
    
        g.optionTitle("Shows the sum of two numbers");
    
        ImageOutput out = new ImageOutput(400,400, g);
        out.render(g);
     
    • Constructor Detail

      • AreaGraph

        public AreaGraph()
    • Method Detail

      • optionCumulative

        public void optionCumulative​(boolean val)
        If this is set to true, the AreaGraph adds the values of the separate curves together to form a total. So if the first curve returned a value of 2 and the second curve returned a value of 3, the second curve would actually be plotted at 5. If your data is already accumulated, set this to false.

        Default: true

      • optionSegments

        public void optionSegments​(boolean val)
        Whether to draw the Area Graph with segments, so that points defined in the data can easily be recognised.

        Default: true

      • complete

        protected void complete()
        Description copied from class: Graph
        Complete is the first method that's called by a Graph when it's rendered. It should take the data from the dataset and add the various elements that it needs to the Graph. The first thing it should do, however, is call super.complete().
        Overrides:
        complete in class Graph
      • plotLine

        protected double plotLine​(int set,
                                  Curve c,
                                  double prevlastval,
                                  double prevval,
                                  double lastx,
                                  double x,
                                  double linewidth,
                                  boolean isLast,
                                  java.util.Map m)
        Description copied from class: AbstractLineGraph
        Actually plot the line. This method needs to be filled in by concrete subclasses of this class. This method must handle NaN and Infinite values. All current subclasses deal with these by skipping those points and leaving a gap in the line.
        Specified by:
        plotLine in class AbstractLineGraph
        Parameters:
        set - The number of the set that's being plotted
        c - The curve that's being plotted
        prevlastval - The value returned by the last X value from the previous set. Set to Double.NaN if there was no previous set, or no last X value.
        prevval - The value returned by this X value from the previous set. Set to Double.NaN if no previous set.
        lastx - The last X value passed in. Set to Double.NaN if no previous X value exists.
        x - The current X value.
        linewidth - The width (or rather depth) of the line to be plotted.
        isLast - Whether this X value is the last value in the set.
        m - A map which can be used by plotLine to pass data between other calls to plotLine. A common use is to set a "start" value if this is the first X value in the set.