title: AchartEngine library : how to redraw, repaint and refresh chart in Android
body: <p>I'm using <em>AchartEngine</em> library for my chart. I have a seekbar for change a chart with value that choose in seekbar. Everytime I choose one a seekbar, my chart not repaint even I have call <code>mChartView.repaint();</code>  and I can't remove a chart before it even I've call <code>removeAllViews();</code>  my chart just make one new top of the last.</p>
  
  <p>This is my code :</p>
  
  <pre><code>   SeekTime.setOnSeekBarChangeListener(new OnSeekBarChangeListener() {
  
          @Override
          public void onStartTrackingTouch(SeekBar seekBar) 
          {
          }
  
          @Override
          public void onProgressChanged(SeekBar seekBar, int progress, boolean fromUser)
          {
          }
          @Override
          public void onStopTrackingTouch(SeekBar seekBar) {
              if (SeekTime.getProgress() &lt;= 3){
                  SeekTime.setProgress(0);
                  period=7;} 
              if (SeekTime.getProgress() &gt; 3 &amp;&amp; SeekTime.getProgress() &lt;= 8){
  
                  SeekTime.setProgress(5);
                  period =30;
              }
              if (SeekTime.getProgress() &gt;8 &amp;&amp; SeekTime.getProgress()&lt;=13){
                  SeekTime.setProgress(10);
                  period = 90;
              }
              if (SeekTime.getProgress() &gt;13 &amp;&amp; SeekTime.getProgress()&lt;=18){
                  SeekTime.setProgress(15);
                  period = 180;
              }
              if (SeekTime.getProgress() &gt;18 &amp;&amp; SeekTime.getProgress()&lt;=23){
                  SeekTime.setProgress(20);
                  period = 270;
              }
          if (SeekTime.getProgress() &gt;23){
                  SeekTime.setProgress(25);
                  period = 360;
                  }
  
              String url = baseURL+"id="+strLjiId+"&amp;nilai="+period;
              new LoadData(url).execute();
  
          }
  
      });
      }   
      @Override
      protected void onResume() {
          // TODO Auto-generated method stub
          super.onResume();
  
          if (mChartView == null) {
               lnChart = (LinearLayout) findViewById(R.id.chart);
                mChartView = ChartFactory.getLineChartView(this, mDataset, mRenderer);
                lnChart.removeAllViews();
                lnChart.addView(mChartView, 0, new LayoutParams(LayoutParams.FILL_PARENT, LayoutParams.FILL_PARENT)); 
   } 
      else {
            mChartView.repaint();
              }
      }
  
      private class LoadData extends AsyncTask&lt;Void, Void, String&gt;{
  
          String url = "";
  
          public LoadData(String url) {
              // TODO Auto-generated constructor stub
              this.url = url;
          }
  
          @Override
          protected void onPreExecute() {
              // TODO Auto-generated method stub
              super.onPreExecute();
  
              dialog = ProgressDialog.show(NABActivityDetail.this, "", "Please wait");
          }
  
          @Override
          protected String doInBackground(Void... params) {
              // TODO Auto-generated method stub
              String result = "";
              try {
                  result = Connection.get(url);
              } catch (Exception e) {
                  // TODO: handle exception
                  result = "";
                  Log.d("TEST CHART", e.getMessage());
              }
  
              return result;
          }
  
          @Override
          protected void onPostExecute(String result) {
              // TODO Auto-generated method stub
              super.onPostExecute(result);
  
              fetchResponse(result.replace("\n", "").trim());
              dialog.dismiss();
          }
  
      }
  
      private void fetchResponse(String result) {
          // TODO Auto-generated method stub
          if (!result.equals("")) {
              try {
                  JSONArray jsonArray = new JSONArray(result);
                  NabDetail item = null;
  
                  for (int i = 0; i &lt; jsonArray.length(); i++) {
  
                      JSONObject jsonObject = jsonArray.getJSONObject(i);
  
              item = new NabDetail(jsonObject.optString("lji_invest"), 
                              jsonObject.optDouble("persen_hmin1"), 
                              jsonObject.optDouble("lnu_nilai"), 
                              jsonObject.optDouble("selisih"), 
                              jsonObject.optDouble("persen_hke1"),
                              jsonObject.optString("tanggal"),
                              jsonObject.optString("lji_id") 
                              );
                      listData.add(item);
                  }
                  renderChart(listData);
  
              } catch (Exception e) {
              }
          }   
      }
  
  
      private void renderChart(ArrayList&lt;NabDetail&gt; listData) {
          // TODO Auto-generated method stub
  
          String seriesTitle = "";
          XYSeries series = new XYSeries(seriesTitle);
          mDataset.addSeries(series);
          mCurrentSeries = series;
          XYSeriesRenderer renderer = new XYSeriesRenderer();
          renderer.setFillBelowLine(true);
          renderer.setFillBelowLineColor(Color.TRANSPARENT);
          renderer.setColor(Color.YELLOW);
          mRenderer.addSeriesRenderer(renderer);
          renderer.setFillPoints(true);
          mCurrentRenderer = renderer;
  
          for (int i = 0; i &lt; listData.size(); i++) {
  
              mCurrentSeries.add(i,listData.get(i).getInuNilai() 
                      );
          }
  
      if (mChartView != null) {
  
               mChartView.repaint();
      }
  </code></pre>
  
  <p>Is there any wrong with my code? Or is there any way to remove the chart before and redraw or refresh new chart?</p>
  
  <p>This is my chart :
  <img src="https://i.stack.imgur.com/gLsr6.png" alt="enter image description here"></p>