I am using MPAndroidChart. When I use the LineChart setDrawFilled() method to fill in the space between the line and the x-axis, and manually adjust the range to be bigger than the default, the filled in portion will go past the x-axis as seen in this screenshot:
The blue fill should stop at the green dotted line, which is over the x-axis, however it extends over it and into positive y-values.
*Upon further investigation, I found only seems to happen when the green line is set to 0.
Another alternative would be to use the FillFormatter
interface provided by the library: https://github.com/PhilJay/MPAndroidChart/blob/master/MPChartLib/src/com/github/mikephil/charting/utils/FillFormatter.java
What this class allows you to do is creating your own logic on where the "filling-line" should end.
Simply implement the FillFormatter
class in your custom formatter class and return the value you want the fill-line to end at.
Example:
class MyCustomFillFormatter implements FillFormatter {
// return the fill position
public float getFillLinePosition(LineDataSet dataSet, LineData data, float chartMaxY, float chartMinY) {
return 0f;
}
}
Inside the getFillLinePosition(...)
method you can of course develop your own logic on where the position of the line should be, depending on various influence factors.
After creating your formatter, set it to the LineChart
:
lineChart.setFillFormatter(new MyCustomFillFormatter());
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With