1

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);
    }
}
Pang
  • 9,564
  • 146
  • 81
  • 122
JenMar
  • 11
  • 3

1 Answers1

0

Without either a DefaultLabelFormatter or a GridLabelFormatter, GraphView will automatically format the graphs labels so that is why you are seeing double values.

Jantzilla
  • 638
  • 1
  • 7
  • 19
  • Thanks a lot for the response I aleready found a way to hide the labels from the xaxis :) – JenMar Jun 01 '18 at 10:06
  • Ok. Sorry i neglected the second part of your question. Were you ever able to get the new data to show up? – Jantzilla Jun 01 '18 at 10:14
  • Yes the data now shows up. The only Problem now is, that I coulnd`t find a way to make an empty bargraph so I filled the graph with the DataPoint 0,0. – JenMar Jun 01 '18 at 10:34
  • No but the problem is, that I can't make an empty bargraph which is filled with datapoints at runtime. – JenMar Jun 01 '18 at 11:27