gpt4 book ai didi

android - 在 Graphview 库中使用日期

转载 作者:塔克拉玛干 更新时间:2023-11-02 08:26:52 25 4
gpt4 key购买 nike

我正在使用 GraphView 库(参见:https://github.com/jjoe64/GraphViewhttp://www.jjoe64.com/p/graphview-library.html)

但我想为 X-as 使用日期/时间。有谁知道一个简单的方法来完成这个或者谁能把我推向正确的方向?

最佳答案

这是执行此操作的正确方法

您只需使用 unix 时间戳(从 1.01.1970 开始的秒数)作为 x 值。

然后你可以设置一个自定义标签格式化器并将unix时间戳转换为一个字符串:

final java.text.DateFormat dateTimeFormatter = DateFormat.getTimeFormat(mActivity);

LineGraphView graphView = new LineGraphView(mActivity, entry.getValue()) {
@Override
protected String formatLabel(double value, boolean isValueX) {
if (isValueX) {
// transform number to time
return dateTimeFormatter.format(new Date((long) value*1000));
} else {
return super.formatLabel(value, isValueX);
}
}
};

关于android - 在 Graphview 库中使用日期,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/10619978/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com