2013-04-09 68 views
1

請幫我,我使用GraphView庫(http://www.jjoe64.com/p/graphview-library.html),它的工作原理。但我不明白如何重置以前的數據。GraphView和resetData

方法redrawAll()不起作用。

IT是我的代碼:

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); 

} 


} 

回答

0

一種方式是去除graphview查看和完全重新創建。

另一種方法是使用實​​時功能。你應該直接從github使用最新版本的graphview。 您可以使用resetDataappendData來更改系列中的數據。看看Github上的GraphView-Demo項目。

exampleSeries1.resetData(new GraphViewData[] { 
     new GraphViewData(1, getRandom()) 
     , new GraphViewData(2, getRandom()) 
     , new GraphViewData(2.5, getRandom()) // another frequency 
     , new GraphViewData(3, getRandom()) 
     , new GraphViewData(4, getRandom()) 
     , new GraphViewData(5, getRandom()) 
}); 
3

我想重置你的意思是清除所有的圖形,然後再繪製一些新的東西?然後你可以使用graphView.removeAllSeries();