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

问题描述

我使用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的。没有人知道一个简单的方法来做到这一点,或任何人都可以把我在正确的方向?

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图形时,创建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.

在code你现在,应该有如下的循环

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;

希望这有助于!

Hope this helped!

这篇关于使用日期与Graphview库的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

09-25 21:39