Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Using dates with the Graphview library

I'm using GraphView library (see: https://github.com/jjoe64/GraphView or http://www.jjoe64.com/p/graphview-library.html)

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?

like image 572
Luciano Avatar asked May 16 '12 13:05

Luciano


1 Answers

This is the correct way to do this

You just have to use the unix timestamp (seconds from 1.01.1970) as x value.

Then you can set a custom label formatter and convert the unix timestamp to a String:

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);
        }
    }
};
like image 73
appsthatmatter Avatar answered Oct 08 '22 11:10

appsthatmatter