0

So, I am making a graphing app(Line Graph), using android GraphView. What I did:

  1. Create a graph view
  2. Create 2 text views(Edit text views that only take numbers), for x and y coordinates
  3. A button that adds the point(x and y coordinates) to the graph and updates the new graph.

I'm calling the button via the following function: writecor(View view)--(Write Coordinates to the graph...)

public void writecor(View view)
{
    GraphView linegraph =  (GraphView)findViewById(R.id.graph);
    EditText xc,yc;
    int xv,yv;
    xc=(EditText)findViewById(R.id.xcor);
    yc=(EditText)findViewById(R.id.ycor);
    xv=Integer.parseInt(xc.getText().toString());
    yv=Integer.parseInt(yc.getText().toString());
    line_series  = new LineGraphSeries<DataPoint>(generatedata());
    line_series.appendData(new DataPoint(xv,yv),true,50);
    line_series.resetData(generatedata());
    linegraph.addSeries(line_series);
}

where generatedata() --(contains preexisting coordinates) is as follows:

private DataPoint[] generatedata()
{
     DataPoint[] values =
             {
             new DataPoint(1,5),
             new DataPoint(2,8),
             new DataPoint(4,7),
             new DataPoint(7,11)
};

The code is obviously wrong, so can you help me?

Laur Ivan
  • 4,117
  • 3
  • 38
  • 62

1 Answers1

0

Try something like this :

DataPoint[] values; 
int size=0; 
private void generateData(int x,int y) {
    values = new DataPoint[size+1];
       DataPoint v = new DataPoint(x, y);
        values[size] = v;
    }

}
public void writecor(View view)
{
GraphView linegraph =  (GraphView)findViewById(R.id.graph);
EditText xc,yc;
int xv,yv;
xc=(EditText)findViewById(R.id.xcor);
yc=(EditText)findViewById(R.id.ycor);
xv=Integer.parseInt(xc.getText().toString());
yv=Integer.parseInt(yc.getText().toString());
generateData(int xv,int yv);
line_series  = new LineGraphSeries<DataPoint>(values);

}
Sneha.G
  • 11
  • 3