2013-07-22 59 views
2

我真的frustased使用achartengine庫,我已經刪除視圖重新繪製圖表,但我的圖表剛剛作出新的頂部圖表上,我真的很困惑...我有搜索任何方法,但我不能得到它..這是我的問題之前:achartengine : how to repaint/redraw chartAchartengine:之前刪除圖表和重繪新的圖表

如何重繪我的圖表,每次我滑到我的搜索條?

這是我的源代碼:

 @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); 
       mChartView.setOnClickListener(new View.OnClickListener() { 
        @Override 
        public void onClick(View v) { 
         SeriesSelection seriesSelection = mChartView.getCurrentSeriesAndPoint(); 
         double[] xy = mChartView.toRealPoint(0); 
         if (seriesSelection == null) { 
          Toast.makeText(getApplicationContext(), "tidak ada chart yang dipilih", Toast.LENGTH_SHORT) 
           .show(); 
          } else { 
         Toast.makeText(
           getApplicationContext(), 
           "Nilai " + listData.get(seriesSelection.getPointIndex()).getInuNilai()+ 
           " tanggal " + listData.get(seriesSelection.getPointIndex()).getTanggal(), 
           Toast.LENGTH_SHORT).show(); 
          } 
        } 
        }); 
       lnChart.addView(mChartView, 0, new LayoutParams(LayoutParams.FILL_PARENT, LayoutParams.FILL_PARENT)); 

      } 
     else { 
mChartView.repaint(); 

      } 
    } 

    public void renderChart(ArrayList<NabDetail> 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); 
     mRenderer.setInScroll(true); 
     mRenderer.setShowLegend(false); 
     //hide x label 
     mRenderer.setXLabels(RESULT_OK); 
     renderer.setFillPoints(true); 
     mCurrentRenderer = renderer; 


     for (int i = 0; i < listData.size(); i++) { 

      mCurrentSeries.add(i,listData.get(i).getInuNilai() 
        ); 

     } 

    if (mChartView != null) { 

     lnChart.removeViewAt(0); 
      mChartView.repaint(); 
     } 
    } 
} 

我已經使用lnChart.removeViewAt(0); mChartView.repaint();但我的圖表還沒有重繪......所以如何重繪和之前刪除圖表?我在哪裏必須輸入正確的代碼?

請..我希望有人能幫助我解決這個問題

回答

5

這段代碼應該爲你工作。

public void renderChart(ArrayList<NabDetail> listData) { 
    // Clear your previous chart DataSet and Renderer. 
    mDataSet.clear(); 
    mRenderer = new XYMultipleSeriesRenderer(); 

    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); 
    mRenderer.setInScroll(true); 
    mRenderer.setShowLegend(false); 
    //hide x label 
    mRenderer.setXLabels(RESULT_OK); 
    renderer.setFillPoints(true); 
    mCurrentRenderer = renderer; 

    for (int i = 0; i < listData.size(); i++) { 
     mCurrentSeries.add(i,listData.get(i).getInuNilai()); 
    } 

    // repaint your chart with new mDataSet and mRenderer. 
    repaint(); 
} 

private void repaint() { 
    lnChart = (LinearLayout) findViewById(R.id.chart); 

    if (mChartView != null) { 
     lnChart.removeView(mChartView); 
    } 

    mChartView = ChartFactory.getLineChartView(this, mDataset, mRenderer); 

    lnChart.addView(mChartView, 0, new LayoutParams(LayoutParams.MATCH_PARENT, LayoutParams.MATCH_PARENT)); 
} 
+0

感謝上帝..!感謝你太Aprian ..其作品..上帝保佑ü.... :) –

+0

mDataSet.clear();變成mDataset.removeSeries(mCurrentSeries); –

+0

工作完美.. – sandeepmaaram