gpt4 book ai didi

android - 如何处理 MPAndroidChart 中的时间序列?

转载 作者:行者123 更新时间:2023-12-04 02:10:23 27 4
gpt4 key购买 nike

我想在 MPAndroidChart 中新引入的时间序列图表中添加以下类型的数据(可以是 1000 以下的任意数量的此类数据对)图书馆

Value :  50.0   at   1472112259
Value : 49.0 at 1472112294
Value : 50.0 at 1472112329
Value : 50.0 at 1472112360
Value : 50.0 at 1472112392

将从数组中获取以下数据。现在,我猜时间戳有些困惑。这是完整的代码:https://gist.github.com/utkarshns/e1723dcc57022fcd392bc3b127b6c898

UNIX 时间戳将在我成功向图表添加值后解析为所需的时间格式。

目前,我面临的问题是时间戳可能会被截断并且值会被覆盖,这会导致图表非常困惑,其中包含非常奇怪的 x 轴值。

更新:截图: http://imgur.com/a/dGfmz

最佳答案

问题是 Float 值不能容纳非常大的数字并且仍然准确,因此您需要一个包含这些时间戳值的单独列表。 BigDecimal 应该可以用于此目的。您的距离必须符合您的事件之间的时间间隔。只需从开始日期到结束日期进行迭代,计算您拥有的时间戳数量,并从您希望的时间戳中添加 Entry 计数。

Long myValues[] = {1472112259L, 1472112294L, 1472112329L, 1472112360L, 1472112392L};// your values

ArrayList<Entry> values = new ArrayList<>();// Entry List
Long start = 1472112259L;//start
Long end = 1472112392L;//end
List<BigDecimal> mList = new ArrayList<>(); //Decimal list which holds timestamps
int count = 0;

for (Long i = start; i <= end; i++) {

mList.add(new BigDecimal(i));
if (myValues.equals(i)) {
values.add(new Entry(count, 50));
}
count++;//always increment
}

你的 ValueFormatter 应该是这样的:

AxisValueFormatter() {

private FormattedStringCache.Generic<Long, Date> mFormattedStringCache = new FormattedStringCache.Generic<>(new SimpleDateFormat("HH:mm:ss"));
@Override
public String getFormattedValue ( float value, AxisBase axis){

return mFormattedStringCache.getFormattedValue(new Date(mList.get((int)value).longValueExact()*1000), value);
}

@Override
public int getDecimalDigits () {
return 0;
}
}

如果您有任何问题或不清楚的地方,我很乐意提供帮助。

关于android - 如何处理 MPAndroidChart 中的时间序列?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/39141121/

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