gpt4 book ai didi

android-graphview - GraphView 和重置数据

转载 作者:行者123 更新时间:2023-12-01 16:55:12 25 4
gpt4 key购买 nike

请帮助我,我使用 GraphView 库( http://www.jjoe64.com/p/graphview-library.html ),它有效。但我不明白如何重置以前的数据。

方法redrawAll()不起作用。

这是我的代码:

   public class MainActivity extends Activity implements OnClickListener{
private final static int DIALOG_ID=0;

@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);

Button btnDialog=(Button)findViewById(R.id.btnDialog);
btnDialog.setOnClickListener(this);

}


@Override
public boolean onCreateOptionsMenu(Menu menu) {
// Inflate the menu; this adds items to the action bar if it is present.
getMenuInflater().inflate(R.menu.activity_main, menu);
return true;
}

@Override
public void onClick(View v) {
// TODO Auto-generated method stub
switch(v.getId()){
case R.id.btnDialog:
createGraph();
break;

}

}

//graph create method
void createGraph(){

// draw sin curve
int num = 100;
GraphViewData[] data = new GraphViewData[num];
GraphView graphView;

double v=0;
for (int i=0; i<num; i++) {
v += 0.50;
data[i] = new GraphViewData(i, Math.random()*v);
}

// graph with dynamically genereated horizontal and vertical labels
graphView = new LineGraphView(
getBaseContext()
, "myGraph"
);




graphView.redrawAll();

((LineGraphView) graphView).setDrawBackground(true);

// add data
graphView.addSeries(new GraphViewSeries(data));
// set view port, start=2, size=10
graphView.setViewPort(2, 40);
graphView.setScalable(true);

LinearLayout layout = (LinearLayout)findViewById(R.id.lvGraphView);
layout.addView(graphView);

}


}

最佳答案

我猜重置你的意思是清除所有图表,然后再次绘制新的东西?然后你可以使用graphView.removeAllSeries();

关于android-graphview - GraphView 和重置数据,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/15913017/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com