Bal*_*vam 6 android mpandroidchart
我正在使用MPAndroidChart库.我正在使用CustomValueFormatter格式化Float值,使其精度为1.
CustomValueFormatter代码:
public class CustomYAxisValueFormatter implements YAxisValueFormatter {
private DecimalFormat mFormat;
public CustomYAxisValueFormatter() {
mFormat = new DecimalFormat("###,###,###,##0.0"); // sets precision to 1
}
@Override
public String getFormattedValue(float value, YAxis yAxis) {
return mFormat.format(value);
}
}
Run Code Online (Sandbox Code Playgroud)
我将格式化程序设置为y轴.
设置格式化程序:
YAxis yAxis = lineChart.getAxisLeft(); //show left y-axis line
yAxis.setValueFormatter(new CustomYAxisValueFormatter()); // set value formatter to format y-values.
Run Code Online (Sandbox Code Playgroud)
因此,默认情况下会创建setValueFormatter(YAxisValueFormatter)上述格式化程序(CustomYAxisValueFormatter).
问题是在缩放时无法重新创建CustomYAxisValueFormatter,从而导致重复的y值.
是否可以创建一个基于缩放级别更改值精度的CustomValueFormatter?
你试过了吗setOnChartGestureListener
lineChart.setOnChartGestureListener(new OnChartGestureListener() {
@Override
public void onChartGestureStart(MotionEvent me, ChartTouchListener.ChartGesture lastPerformedGesture) {
}
@Override
public void onChartGestureEnd(MotionEvent me, ChartTouchListener.ChartGesture lastPerformedGesture) {
if(lastPerformedGesture == ChartTouchListener.ChartGesture.PINCH_ZOOM) {
YAxis yAxis = lineChart.getAxisLeft(); //show left y-axis line
yAxis.setValueFormatter(new CustomYAxisValueFormatter()); // setting your new value formatter
}
}
@Override
public void onChartLongPressed(MotionEvent me) {
}
@Override
public void onChartDoubleTapped(MotionEvent me) {
}
@Override
public void onChartSingleTapped(MotionEvent me) {
}
@Override
public void onChartFling(MotionEvent me1, MotionEvent me2, float velocityX, float velocityY) {
}
@Override
public void onChartScale(MotionEvent me, float scaleX, float scaleY) {
}
@Override
public void onChartTranslate(MotionEvent me, float dX, float dY) {
}
});
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
2143 次 |
| 最近记录: |