我正在为我的项目使用 MPAndroidChart,但我遇到了问题。
看起来,每次,当我在条形图 View 上设置新数据时,即使我使用 clear() 方法,出于某些原因,也会创建左填充。请问,我该如何解决?
最佳答案
我们也有同样的问题。显然,方法 clear() 不会将值数组 YAxis 归零。此外,方法 computeAxisValues(float min, float max) 不会检查 YAxis 的旧值数组的长度何时大于新值的计数。
在您的例子中,当您从 Chart3 切换到 Chart1 时,首先:
yAxis.mEntries = [0, 2000, 4000, 6000, 8000, 10000, 12000, 14000, 16000, 18000]
第二种情况:
yAxis.mEntries = [0, 30, 60, 90, 120, 150, 180, 210, 240, 18000]
这就是为什么 BarChart View 需要从左边填充,以获得比实际需要更大的值。
您可以使用该 hack 来检查您的案例:
YAxis yAxis = barChart.getAxisLeft();
if (yAxis.mEntries.length > yAxis.mEntryCount){
float[] arr = yAxis.mEntries;
yAxis.mEntries = new float[yAxis.mEntryCount];
System.arraycopy(arr, 0, yAxis.mEntries, 0, yAxis.mEntryCount);
}
关于android - 在 MPAndroidChart 库的 BarChart View 上设置新数据时的左填充,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/43192135/