I´m not very good at programming, but I need to build an App where you can type in Datapoints and after clicking a button the datapoint should be added to a graph. I started with a bar graph and it works, but for some reason the labels are in doubles, even if I type in 1 the bar is between 0.8 an 1.2 on the xaxis and the first 3 datapoints I type in doesn't show up.
Please excuse my bad english (and my bad programming).
public class BalkenActivity extends AppCompatActivity implements View.OnClickListener{
GraphView bargraph;
BarGraphSeries<DataPoint> series;
double xval = 1;
double yval;
TextView texty;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_balken);
Button button1 = findViewById(R.id.addbtn);
button1.setOnClickListener(this);
texty = findViewById(R.id.yvalue);
bargraph = findViewById(R.id.bargraph);
series = new BarGraphSeries<>(getDataPoint());
}
private DataPoint[] getDataPoint() {
DataPoint[] dp = new DataPoint[]
{
new DataPoint(0,0),
};
return dp;
}
public void onClick (View v) {
yval = new Double(texty.getText().toString()).doubleValue();
series.appendData(new DataPoint(xval++,yval),true,100);
bargraph.addSeries(series);
bargraph.getViewport().setScalable(true);
bargraph.getViewport().setMinX(0);
series.setSpacing(50);
series.setDrawValuesOnTop(true);
series.setValuesOnTopColor(Color.BLACK);
}
}