Reputation: 5343
The bug is, using FillOutsideLine.Type.BOUNDS_BELOW
, if a line crosses the horizon (y == 0), then immediately crosses again, the fill leaks out of the line borders. Here's a screenshot:
(Also notice that the fill leaks out the bottom of the curve. We don't have that problem but it might be a bug too.)
I'll put the sample code in a Gist but the heart of it is:
private void initChart() {
mCurrentSeries = new XYSeries("Sample Data");
mHorizon = new XYSeries("Horizon");
mDataset.addSeries(mCurrentSeries);
mDataset.addSeries(mHorizon);
mCurrentRenderer = new XYSeriesRenderer();
mCurrentRenderer.setPointStyle(PointStyle.CIRCLE);
mCurrentRenderer.setFillPoints(true);
mRenderer.addSeriesRenderer(mCurrentRenderer);
mHorizonRenderer = new XYSeriesRenderer();
mHorizonRenderer.setColor(Color.GRAY);
mRenderer.addSeriesRenderer(mHorizonRenderer);
XYSeriesRenderer.FillOutsideLine fill = new XYSeriesRenderer.FillOutsideLine(XYSeriesRenderer.FillOutsideLine.Type.BOUNDS_BELOW);
int transparentRed = Color.argb(0.10F, 1.0F, 0.0F, 0.0F);
fill.setColor(transparentRed);
mCurrentRenderer.addFillOutsideLine(fill);
}
private void addSampleData() {
mHorizon.add(1, 0);
mHorizon.add(7, 0);
mCurrentSeries.add(1, 2);
mCurrentSeries.add(2, 3);
mCurrentSeries.add(3, 2);
mCurrentSeries.add(4, -5);
mCurrentSeries.add(5, 4);
mCurrentSeries.add(6, -3);
mCurrentSeries.add(7, 5);
}
The Gist is: https://gist.github.com/Phlip/f79b3b5bd44663b3bd72e173fc5dce13
Similar traffic on this bug says to switch to BOUNDS_ALL
and I can't do that because my requirement is that only one boundary needs the color fill.
(I have tweaked our copy of AchartEngine to set the boundary to something other than the horizon line, if anyone is interested, but the tweak did not cause the bug. This example program uses a fresh download from https://github.com/ddanny/achartengine/ )
Upvotes: 1
Views: 41
Reputation: 5343
The fix is to edit LineChart.java
and comment out this i += 2
:
if (fill.getType() == FillOutsideLine.Type.BOUNDS_ABOVE && value > referencePoint
|| fill.getType() == FillOutsideLine.Type.BOUNDS_BELOW && value < referencePoint) {
// i += 2;
add = false;
} else {
The result now looks like this, which is good enough for us because we don't use a spline:
Upvotes: 1