So, I am making a graphing app(Line Graph), using android GraphView. What I did:
- Create a graph view
- Create 2 text views(Edit text views that only take numbers), for x and y coordinates
- 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?