当Y轴的数值范围为-200到0时(即全为负值),如果我们在代码中设置了:
mLineDataSet.setDrawFilled(true);
那么具体的效果会如下所示:

这显然跟我们想要的效果不一致,我们需要的是填充折线到X轴之间的空间,那么怎么样做到这样的效果呢?
其实MPAndroidChart给我们提供了一个IFillFormatter接口,先来看一下接口描述:
Interface for providing a custom logic to where the filling line of a LineDataSet should end. This of course only works if setFillEnabled(...) is set to true.
这其实就是一个设置填充线的接口, 接口中唯一的方法也很好理解,就是根据你的自定义需求去设置填充线的位置。
那么接下来就好办了,我们在代码中加入:
mLineDataSet.setFillFormatter(new IFillFormatter() {
@Override
public float getFillLinePosition(ILineDataSet dataSet, LineDataProvider dataProvider) {
return mLeftAxis.getAxisMini

本文介绍如何使用MPAndroidChart库在Android应用中实现折线图填充效果,特别是当Y轴全为负值时,通过实现IFillFormatter接口自定义填充线位置,使其正确填充至X轴。

1622

被折叠的 条评论
为什么被折叠?



