Search code examples
javaandroidchartsandroidplot

AndroidPlot and RectRegion behavior


Hello iam trying to show a rect for a bmi graph.

but the rect will be cut and hidden on scroll event

EDIT: the green rect should be

Point A(-infinity, 21) Point B(+infinity, 21) Point C(+infinity, 26) Point D(-infinity, 26)

But Point B is (12.10, 21) //12.10 is a date 12-10-2012

    // optimal_range
    LineAndPointFormatter optFormat = new LineAndPointFormatter(Color.TRANSPARENT, Color.TRANSPARENT, Color.TRANSPARENT);
    XYRegionFormatter rf = new XYRegionFormatter(optimal_color_fill);
    RectRegion rr = new RectRegion(Double.NEGATIVE_INFINITY, Double.POSITIVE_INFINITY, optimal[0], optimal[1]);

    Number xDummy[] = { Double.NEGATIVE_INFINITY, Double.POSITIVE_INFINITY };
    Number yDummy[] = { optimal[1], optimal[1] };
    XYSeries optSerie = new SimpleXYSeries(Arrays.asList(xDummy), Arrays.asList(yDummy), "");
    mySimpleXYPlot.addSeries(optSerie, optFormat);

Rect problem


Solution

  • It's a while since I looked at the code for this and I never did anything with regions but I think if you pan and zoom so that data is off the screen the points off screen are just not drawn and this leads to what you are seeing. To get things correct there is a need to clip the line segment going off the screen to the screen edges.