MPAndroidChart:每个缩放级别的不同 xValues
MPAndroidChart: Different xValues for each zoom level
考虑一个以年作为 xValues 的图表。我想在用户放大或双击时将 xValues 更改为几个月。并将 xValues 更改为下一个缩放级别的天数。
MPAndroidChart 有可能吗?
我会玩这个功能
float displayed = totalitemcount/30;
mChart.setScaleMinima(displayed, 1f);
我已将其设置为显示 30 个值,但您可以将其设置为显示任何您需要更改的值,并在用户双击屏幕时更改标签。
这是我的解决方案:
xl.setValueFormatter(new XAxisValueFormatter() {
@Override
public String getXValue(String original, int index, ViewPortHandler viewPortHandler) {
int months= index/30, days= index%30;
if (days==0) return String.format(Locale.ENGLISH, "%d months", months);
return String.format(Locale.ENGLISH, "%s%s",
months == 0 ? "" : String.format(Locale.ENGLISH, "%d months and ", months),
String.format(Locale.ENGLISH, "%d days", days));
}
});
@Override
public void onChartScale(MotionEvent me, float scaleX, float scaleY) {
int nLabelsToSkip= Math.min(30, Math.max((int) (120 / mChart.getViewPortHandler().getScaleX()), 0));
nLabelsToSkip = (nLabelsToSkip/5) * 5 -1; // (n+1) should be dividable by 5
mChart.getXAxis().setLabelsToSkip(nLabelsToSkip);
}
完全缩小:0 个月、1 个月、2 个月...
缩放级别 1:0 个月、0 个月又 15 天、1 个月、1 个月又 15 天,...
缩放级别 2:0 个月、0 个月又 10 天、0 个月又 20 天、1 个月、1 个月又 10 天,...
缩放级别 3:0 个月,0 个月零 5 天,0 个月零 10 天,0 个月零 15 天,0 个月零 20 天,0 个月零 25 天,1 个月,...
缩放级别 n:0 个月、0 个月零 1 天、0 个月零 2 天、...
感谢伟大的图书馆@PhilJay。
考虑一个以年作为 xValues 的图表。我想在用户放大或双击时将 xValues 更改为几个月。并将 xValues 更改为下一个缩放级别的天数。 MPAndroidChart 有可能吗?
我会玩这个功能
float displayed = totalitemcount/30;
mChart.setScaleMinima(displayed, 1f);
我已将其设置为显示 30 个值,但您可以将其设置为显示任何您需要更改的值,并在用户双击屏幕时更改标签。
这是我的解决方案:
xl.setValueFormatter(new XAxisValueFormatter() {
@Override
public String getXValue(String original, int index, ViewPortHandler viewPortHandler) {
int months= index/30, days= index%30;
if (days==0) return String.format(Locale.ENGLISH, "%d months", months);
return String.format(Locale.ENGLISH, "%s%s",
months == 0 ? "" : String.format(Locale.ENGLISH, "%d months and ", months),
String.format(Locale.ENGLISH, "%d days", days));
}
});
@Override
public void onChartScale(MotionEvent me, float scaleX, float scaleY) {
int nLabelsToSkip= Math.min(30, Math.max((int) (120 / mChart.getViewPortHandler().getScaleX()), 0));
nLabelsToSkip = (nLabelsToSkip/5) * 5 -1; // (n+1) should be dividable by 5
mChart.getXAxis().setLabelsToSkip(nLabelsToSkip);
}
完全缩小:0 个月、1 个月、2 个月...
缩放级别 1:0 个月、0 个月又 15 天、1 个月、1 个月又 15 天,...
缩放级别 2:0 个月、0 个月又 10 天、0 个月又 20 天、1 个月、1 个月又 10 天,...
缩放级别 3:0 个月,0 个月零 5 天,0 个月零 10 天,0 个月零 15 天,0 个月零 20 天,0 个月零 25 天,1 个月,...
缩放级别 n:0 个月、0 个月零 1 天、0 个月零 2 天、...
感谢伟大的图书馆@PhilJay。