title: android dynamic plot using Achartengine
body: <p>i m new to android. I m using Achartengine to plot a dynamic graph reading values from a binary file. Given below is my code.I want to have a dynamic running graph, in which values are being updated regularly. For this i tries to do it with and without a timer. But every time i am getting the graph with the final values when the last values have been updated. I mean i m getting a static graph after all the updates have been done. I can't figure out how to correct this. I am using the emulator to test the code. Could there be some problem with the emulator or something wrong with my code ? Thanks in advance</p>
  
  <p>code without timer :</p>
  
  <pre><code>public class RandomActivity extends Activity {
  private XYMultipleSeriesDataset eeg1 = new XYMultipleSeriesDataset();
  private XYMultipleSeriesRenderer renderer_eeg1 = new XYMultipleSeriesRenderer();
  private XYSeries series1;
  private GraphicalView view_eeg1;
  
  
  public void onCreate(Bundle savedInstanceState) {
  super.onCreate(savedInstanceState);
  setContentView(R.layout.main);
  
  renderer_eeg1.setAxisTitleTextSize(16);
  renderer_eeg1.setChartTitleTextSize(20);
  renderer_eeg1.setLabelsTextSize(15);
  renderer_eeg1.setLegendTextSize(15);
  renderer_eeg1.setMargins(new int[] {20, 30, 15, 0});
  renderer_eeg1.setAxesColor(Color.BLUE);
  renderer_eeg1.setXTitle("Time");
  renderer_eeg1.setChartTitle("eeg1");
  XYSeriesRenderer seriesrenderer1 = new XYSeriesRenderer();
  seriesrenderer1.setColor(Color.YELLOW);
  renderer_eeg1.addSeriesRenderer(seriesrenderer1); 
  series1= new XYSeries("eeg1");
  eeg1.addSeries(series1);
  int a;
  int b;
  add();
  
  for(int r=0;r&lt;=600;r++){
  
     if(r%2==0){
        a=1;
        b=-1;
     }
     else{
        a=-1;
        b=1;
     }
  
     series1.add(r, a);
         if(r&lt;=50){
        renderer_eeg1.setXAxisMax(50);
         }
         else if(r&gt;50){
            double maxX = series1.getMaxX();
        double minX = maxX - 50;
            renderer_eeg1.setXAxisMin(minX);
         }
         view_eeg1.repaint();
  }
  }
  
  
  protected void onResume() {
  super.onResume();  
  if (view_eeg1== null) {
  LinearLayout layout_eeg1 = (LinearLayout) findViewById(R.id.chart1);
  view_eeg1= ChartFactory.getLineChartView(this, eeg1, renderer_eeg1);
  layout_eeg1.addView(view_eeg1,new LayoutParams(LayoutParams.FILL_PARENT,  LayoutParams.FILL_PARENT));
  } else {
   view_eeg1.repaint();}
  }
  
  }
  </code></pre>
  
  <p>code with timer :</p>
  
  <pre><code>public class RandomActivity extends Activity {
  private XYMultipleSeriesDataset eeg1 = new XYMultipleSeriesDataset();
  private XYMultipleSeriesRenderer renderer_eeg1 = new XYMultipleSeriesRenderer();
  private XYSeries series1;
  private GraphicalView view_eeg1;
  
  
  public void onCreate(Bundle savedInstanceState) {
  super.onCreate(savedInstanceState);
  setContentView(R.layout.main);
  
  renderer_eeg1.setAxisTitleTextSize(16);
  renderer_eeg1.setChartTitleTextSize(20);
  renderer_eeg1.setLabelsTextSize(15);
  renderer_eeg1.setLegendTextSize(15);
  renderer_eeg1.setMargins(new int[] {20, 30, 15, 0});
  renderer_eeg1.setAxesColor(Color.BLUE);
  renderer_eeg1.setXTitle("Time");
  renderer_eeg1.setChartTitle("eeg1");
  XYSeriesRenderer seriesrenderer1 = new XYSeriesRenderer();
  seriesrenderer1.setColor(Color.YELLOW);
  renderer_eeg1.addSeriesRenderer(seriesrenderer1); 
  series1= new XYSeries("eeg1");
  eeg1.addSeries(series1);
  int a;
  int b;
  add();
  
  for(int r=0;r&lt;=600;r++){
  
        Thread timer = new Thread(){
              public void run(){
                  try{
                      sleep(500);
                  } catch (InterruptedException e) {
                      // TODO Auto-generated catch block
                      e.printStackTrace();
                  } 
              }
          };
  
  
     if(r%2==0){
        a=1;
        b=-1;
     }
     else{
        a=-1;
        b=1;
     }
  
     series1.add(r, a);
         if(r&lt;=50){
        renderer_eeg1.setXAxisMax(50);
         }
         else if(r&gt;50){
            double maxX = series1.getMaxX();
        double minX = maxX - 50;
            renderer_eeg1.setXAxisMin(minX);
         }
         view_eeg1.repaint();
  }
  }
  
  
  protected void onResume() {
  super.onResume();  
  if (view_eeg1== null) {
  LinearLayout layout_eeg1 = (LinearLayout) findViewById(R.id.chart1);
  view_eeg1= ChartFactory.getLineChartView(this, eeg1, renderer_eeg1);
  layout_eeg1.addView(view_eeg1,new LayoutParams(LayoutParams.FILL_PARENT,  LayoutParams.FILL_PARENT));
  } else {
   view_eeg1.repaint();}
  }
  
  }
  </code></pre>