我正在使用Graphview与数据库中的DataPoint[]。DataPoint[]的数据点如下。
我的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);
结果就是这个图形。
正如你所看到的,X轴上除了第一个和最后一个以外,其他的都不是我的数据点的x值,也不是直接在一个特定的数据点下。它们是在我的数据点的第一个和最后一个x值之间的范围内的数据值,它们之间的距离是不一样的。时间越长,x值之间的距离就越大。
我想用我的数据点的精确x值作为X轴标签,而不是其他X轴标签,并且无论日期之间的时间有多长,数据点之间的距离都应该是相同的。
我如何才能做到这一点?