Trying to add date in X axis - GraphView for Android

I need help, I want to show my GraphView date on DD / MM / YYYY on x axis. And in the y-axis number (Integer) ... how can I add the date to the X-axis, it only gets an int. (I am using this library http://android-graphview.org/ )

+3


source to share


2 answers


You can use a custom list of horizontal labels, for example:

barGraphView.setHorizontalLabels(new String[]{"1/1/1970", "1/2/1970", "1/3/1970"});

      



I did something similar by constructing a String array using a for loop.

+1


source


There is a post about this topic in this documentation:

http://www.android-graphview.org/documentation/label-formatter

There is also a specific example for dates in the axis - "Use dates as labels".



If you set the X value as a Date object or as unix epoch (millis from 1970-01-01) you can easily use this predefined label format:

graph.getGridLabelRenderer().setLabelFormatter(new DateAsXAxisLabelFormatter(getActivity()));

      

+4


source







All Articles