问题描述
我正在使用 GraphView 库(请参阅:https://github.com/jjoe64/GraphView 或 http://www.jjoe64.com/p/graphview-library.html)
I'm using GraphView library (see: https://github.com/jjoe64/GraphView or http://www.jjoe64.com/p/graphview-library.html)
但我想为 X-as 使用日期/时间.有没有人知道一种简单的方法来实现这一目标,或者任何人都可以将我推向正确的方向?
But I would like to use Date/Time for the X-as. Does anyone knows a easy way to accomplish this or can anyone push me in the right direction?
推荐答案
GraphView 是一个很好用的库,我发现它也是最简单的.执行此操作的第一步是在 GraphView.java 的 GraphViewData 类中添加一个字符串变量.像这样:
GraphView is a great library to use, i find it the easiest as well. The first step in doing this would be to add a String Variable in the GraphViewData Class within GraphView.java. Like So:
static public class GraphViewData {
public final double valueX;
public final double valueY;
public final String valueDate;
public GraphViewData(double valueX, double valueY,String valueDate) {
super();
this.valueX = valueX;
this.valueY = valueY;
this.valueDate = valueDate;
}
}
当您在创建 GraphView Graph 时创建 GraphViewData 对象时,您需要以字符串形式添加日期数据(以及 X 和 Y).
When you create your GraphViewData object when creating a GraphView Graph, you will need to add the date data in string form (along with the X and Y).
假设您的图表中有 80 个数据点(索引 0 - 79).GraphView 中有一个方法负责生成和返回水平标签,我相信它叫做 generateHorLabels.不是仅仅返回 X 值 (0-79),而是使用 X 值从 GraphData 对象获取字符串.
Lets say you have 80 data points in your graph (index 0 - 79). There is a method within GraphView that is responsible for generating and returning the horizontal labels, i believe its called generateHorLabels. Instead of just returning the X Value (0-79), Use the X value to get the String from the GraphData object.
在您现在拥有的代码中,它应该在 for 循环中具有以下内容
In the code you have now, it should have the following in a for loop
labels[i] = formatLabel(min + ((max-min)*i/numLabels), true);
你可以做这样的事情,而不是上面的.
instead of the above, you could do something like this.
Double temp = Double.valueOf(formatLabel(min + ((max-min)*i/numLabels), true));
int rounded =(int)Math.round(temp);
labels[i] = values[rounded].valueDate;
希望这有帮助!
这篇关于在 Graphview 库中使用日期的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!