I am using the Graphview with a DataPoint[] from a database. The DataPoint[] has the following datapoints:
- [1.582381477E12/0.0] (date is 2020-02-22 14:24:37),
- [1.58238148E12/1.0] (date is 2020-02-22 14:24:40),
- [1.582381489E12/2.0] (date is 2020-02-22 14:24:49),
- [1.582381491E12/3.0] (date is 2020-02-22 14:24:51),
- [1.582381497E12/4.0] (date is 2020-02-22 14:24:57),
- [1.582381511E12/5.0] (date is 2020-02-22 14:25:11)
I`m using this code for my GraphView:
DataPoint[] dataPoints = getSucccessData(exercise.getExersiseNumber());
LineGraphSeries<DataPoint> mLGS = new LineGraphSeries<>(dataPoints);
mLGS.setDrawDataPoints(true);
graphView = findViewById(R.id.gvGraphView);
simpleDateFormat = new SimpleDateFormat("dd-M-yyyy hh:mm:ss");
graphView.getGridLabelRenderer().setLabelFormatter(new DefaultLabelFormatter(){
@Override
public String formatLabel(double value, boolean isValueX) {
if(isValueX){
return simpleDateFormat.format(new Date((long)value));
}
else {
return super.formatLabel(value, isValueX);
}
}
});
graphView.removeAllSeries();
graphView.addSeries(mLGS);
graphView.getViewport().setMinY(0);
graphView.getViewport().setMaxY(5);
graphView.getViewport().setYAxisBoundsManual(true);
graphView.getViewport().setMinX(dataPoints[0].getX());
graphView.getViewport().setMaxX(dataPoints[dataPoints.length - 1].getX());
graphView.getGridLabelRenderer().setNumHorizontalLabels(dataPoints.length -1);
graphView.getViewport().setXAxisBoundsManual(true);
graphView.getGridLabelRenderer().setHumanRounding(false, true);
graphView.getGridLabelRenderer().setHorizontalLabelsAngle(90);
graphView.getViewport().setScrollableY(true);
graphView.getViewport().setScrollableY(true);
graphView.getViewport().setScalable(true);
graphView.getViewport().scrollToEnd();
graphView.getViewport().setScrollable(true);
The result ist this Graph:
As you can see the Xaxis labes are except from the first and the last one not the x-Values of my datapoints and they are not directly unter a specific datapoint. They are datevalues in a range between the first and the last x-Value of my datapoints and the distance between them is not the same. The more time is between the x-Values the more distance is between the datapoints.
I want to have the exact x-Value of my datapoints as Xaxis-Label, no other Xaxis-Labels and the distance between the datapoints should always be the same no matter how much time is between the dates.
How can I do this?