本文介绍了使用Graphview库的日期的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我使用GraphView库(请参阅:或)

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类中添加一个String变量。像这样:

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对象获取String。

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.

在您现在的代码中,它应该在循环

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库的日期的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

10-28 10:51