Using dates with the Graphview library

后端 未结 4 1474
时光取名叫无心
时光取名叫无心 2020-12-31 11:50

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

4条回答
  •  悲哀的现实
    2020-12-31 12:33

    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);
            }
        }
    };
    

提交回复
热议问题