XAxis 标签到时间 (mm:ss) 与 MPAndroidChart
XAxis labels to time (mm:ss) with MPAndroidChart
我想在我的 MPAndroidChart 折线图上将 XAxis 标签显示为以分钟和秒为单位的时间 mm:ss
。我试图创建一个 ValueFormatter,但是,IAxisValueFormatter
和 getFormattedValue
似乎已被弃用。
我每秒有 40 帧,因此对于每 40 帧,标签应增加 00:01,并在 00:59 变为 01:00 时更改。
你能帮我实现这个吗?
到目前为止,我的 valueformatter 代码是:
xAxis.setValueFormatter(new MyFormatter());
public class MyFormatter implements IAxisValueFormatter {
@Override
public String getFormattedValue(float value, AxisBase axis) {
int second = (int) value / 40
return second + "s" //make it a string and return
}
试试这个:
import android.util.Log;
import com.github.mikephil.charting.components.AxisBase;
import com.github.mikephil.charting.formatter.ValueFormatter;
public class XAxisValueFormatter extends ValueFormatter {
@Override
public String getAxisLabel(float value, AxisBase axis) {
Log.d("ADebugTag", "Value: " + Float.toString(value));
int axisValue = (int) value/40;
if (axisValue >= 0) {
String sh = String.format("%02d:%02d", (axisValue / 3600 * 60 + ((axisValue % 3600) / 60)), (axisValue % 60));
return sh;
} else {
return "";
}
}
}
我想在我的 MPAndroidChart 折线图上将 XAxis 标签显示为以分钟和秒为单位的时间 mm:ss
。我试图创建一个 ValueFormatter,但是,IAxisValueFormatter
和 getFormattedValue
似乎已被弃用。
我每秒有 40 帧,因此对于每 40 帧,标签应增加 00:01,并在 00:59 变为 01:00 时更改。
你能帮我实现这个吗?
到目前为止,我的 valueformatter 代码是:
xAxis.setValueFormatter(new MyFormatter());
public class MyFormatter implements IAxisValueFormatter {
@Override
public String getFormattedValue(float value, AxisBase axis) {
int second = (int) value / 40
return second + "s" //make it a string and return
}
试试这个:
import android.util.Log;
import com.github.mikephil.charting.components.AxisBase;
import com.github.mikephil.charting.formatter.ValueFormatter;
public class XAxisValueFormatter extends ValueFormatter {
@Override
public String getAxisLabel(float value, AxisBase axis) {
Log.d("ADebugTag", "Value: " + Float.toString(value));
int axisValue = (int) value/40;
if (axisValue >= 0) {
String sh = String.format("%02d:%02d", (axisValue / 3600 * 60 + ((axisValue % 3600) / 60)), (axisValue % 60));
return sh;
} else {
return "";
}
}
}