所以,我正在使用android GraphView制作一个图形应用程序(Line Graph)。 我做了什么:
我通过以下功能调用按钮:writecor(View view)
- (将坐标写入图表...)
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);
}
其中generatedata()
- (包含预先存在的坐标)如下:
private DataPoint[] generatedata()
{
DataPoint[] values =
{
new DataPoint(1,5),
new DataPoint(2,8),
new DataPoint(4,7),
new DataPoint(7,11)
};
代码显然是错误的,你能帮助我吗?
答案 0 :(得分:0)
尝试这样的事情:
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);
}