GraphView 不显示第一个数据点
GraphView is not displaying first Datapoint on tap
这些代码应该绘制一个图形,然后在点击时,它应该将相应的数据点显示为 toast 通知。一切正常,除了第一个数据点没有在点击时显示(x=1,y=数量)。它只显示 (x=2,y=amount).
public void DrawGraph(int term, double amount, Float P, Float r, GraphView graph){
graph.setVisibility(View.VISIBLE);
graph.getViewport().setScrollable(true);
graph.getViewport().setScrollableY(true);
graph.getViewport().setMinX(0);
graph.getViewport().setMaxX(term+1);
graph.getViewport().setMinY(0);
graph.getViewport().setMaxY(Math.round(amount)*1.15);
graph.getViewport().setYAxisBoundsManual(true);
graph.getViewport().setXAxisBoundsManual(true);
graph.removeAllSeries();
LineGraphSeries<DataPoint> series = new LineGraphSeries<>();
for (int i=1;i<=term;i++){
int x=i;
long y=Math.round(P * java.lang.Math.pow(1 + (r) / 100, i));
series.appendData(new DataPoint(x,y),true,term);
}
graph.addSeries(series);
series.setOnDataPointTapListener(new OnDataPointTapListener() {
@Override
public void onTap(Series series, DataPointInterface dataPoint) {
Toast.makeText(SinglePremium.this,"After "+(int)dataPoint.getX()+" years amount becomes "+(long)dataPoint.getY(),Toast.LENGTH_LONG).show();
}
});
}
这行代码解决了这个问题。
series.setDrawDataPoints(true);
这里series是LineGraphSeries的一个对象。
这些代码应该绘制一个图形,然后在点击时,它应该将相应的数据点显示为 toast 通知。一切正常,除了第一个数据点没有在点击时显示(x=1,y=数量)。它只显示 (x=2,y=amount).
public void DrawGraph(int term, double amount, Float P, Float r, GraphView graph){
graph.setVisibility(View.VISIBLE);
graph.getViewport().setScrollable(true);
graph.getViewport().setScrollableY(true);
graph.getViewport().setMinX(0);
graph.getViewport().setMaxX(term+1);
graph.getViewport().setMinY(0);
graph.getViewport().setMaxY(Math.round(amount)*1.15);
graph.getViewport().setYAxisBoundsManual(true);
graph.getViewport().setXAxisBoundsManual(true);
graph.removeAllSeries();
LineGraphSeries<DataPoint> series = new LineGraphSeries<>();
for (int i=1;i<=term;i++){
int x=i;
long y=Math.round(P * java.lang.Math.pow(1 + (r) / 100, i));
series.appendData(new DataPoint(x,y),true,term);
}
graph.addSeries(series);
series.setOnDataPointTapListener(new OnDataPointTapListener() {
@Override
public void onTap(Series series, DataPointInterface dataPoint) {
Toast.makeText(SinglePremium.this,"After "+(int)dataPoint.getX()+" years amount becomes "+(long)dataPoint.getY(),Toast.LENGTH_LONG).show();
}
});
}
这行代码解决了这个问题。
series.setDrawDataPoints(true);
这里series是LineGraphSeries的一个对象。