Using dates with the Graphview library

后端 未结 4 1461
时光取名叫无心
时光取名叫无心 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:30

    Here's the updated answer from jjoe64, with the x-values obtained from Date#getTime()

        final DateFormat dateTimeFormatter = DateFormat.getDateTimeInstance();        
        graphView = new LineGraphView(context, "Chart");
        graphView.setCustomLabelFormatter(new CustomLabelFormatter() 
        {
            @Override
            public String formatLabel(double value, boolean isValueX) 
            {
                if (isValueX)
                {
                    return dateTimeFormatter.format(new Date((long) value));
                }
                return null; // let graphview generate Y-axis label for us
            }
        });
    

提交回复
热议问题