2

我真的很沮丧使用 achartengine 库重绘图表,我有删除视图,但我的图表只是在顶部图表上新建,我真的很困惑......我有搜索任何方法但我无法得到它..这是我之前的问题: achartengine : 如何重绘/重绘图表

每次滑动搜索栏时如何重绘图表?

这是我的源代码:

        @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();,但我的图表仍然没有重绘……那么以前如何重绘和删除图表?我必须在哪里输入正确的代码?

请..我希望有人能帮我解决这个问题

4

1 回答 1

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));
}
于 2013-07-22T05:07:08.957 回答