Open EXJUSTICE opened 7 years ago
I have the same issue. The date is a long but the Entry class only accepts float so you get an inaccurate reading when drawing the graph.
My solution was to get the first item in the array time as a long. then minus that from all the points before putting them into the graph.
if(points.size() >0){ long firstTimeStamp = points.get(0).getTimeStamp().getTime(); for(MoodLog point : points) { Date date = point.getTimeStamp(); long time = date.getTime()- firstTimeStamp; float x = time; float y = point.getScore(); entries.add(new Entry(x,y)); xAxisLabels.add(point.getDateShort()); }
If you're using a unix timestamp, the problem is when it gets converted to Float, it loses precision, so lots of timestamps that actually represent different times end up being rounded and represented as the same x value. See #2891
I've previously and successfully implemented a linechart featuring an x-axis by using the method recommended by PhilJay, where a set of index integers are shared between the y and x-datasets.
I have heard that it is possible now with ver. 3+ to directly use timestamps on the x-axis, with an IAxisValueFormatter converting them to string dates. However, I am experiencing a strange situation where the data is all displayed at x=0, with no plotting or x-axis labels whatsoever.
The system works as this: SQLite creates a datetime value, which I convert into a date, and then into a long timestamp. I've checked the validity of the timestamps by having them printed, theyre solid.
This is my method for making LineDataSets
Any advice would be appreciated. I am running version 3.0.2.