javaandroidandroidplot

How to fill area between 2 series in Androidplot?


I have 2 dynamic series that I keep updating and I want to fill the area between the 2 series with color (sort of like a moving window). This question has the solution for plain canvas, but I'd like to do the same using androidplot. How should I approach this? Thanks.


Solution

  • I actually figured it out by extending the LineAndPointRenderer class and building a "fill" series that combines the 2 series I have. The "fill" series is essentially the same as the path suggested in the other Stackoverflow answer I mentioned in the question; I add the first point of the first series, then all of the points in the second, before looping back for the remaining points of the first one (the "fill" series is now closed and sort of like a "rectangle"). In the custom renderer extending the LineAndPointRenderer class I override the renderPath method, modifying this part:

    switch (formatter.getFillDirection()) {
                case FILL:
                    path.lineTo(lastPoint.x, lastPoint.y);
                    path.close();
                    break;
                default:
                    throw new UnsupportedOperationException(
                            "Fill direction not yet implemented: " + formatter.getFillDirection());
            }
    

    Everything else stays the same.