在 MPAndroidChart 库的 BarChart View 上设置新数据时的左填充
Left padding when set new data on BarChart View from MPAndroidChart library
我正在为我的项目使用 MPAndroidChart,但我遇到了问题。
看起来,每次,当我在条形图视图上设置新数据时,即使我使用 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);
}
我正在为我的项目使用 MPAndroidChart,但我遇到了问题。
看起来,每次,当我在条形图视图上设置新数据时,即使我使用 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);
}