Achartengine重新粉刷

时间:2012-02-16 17:18:04

标签: android charts android-linearlayout repaint achartengine

我在webservice中有一个数据连接。在Assynctask中,我每5秒获取一次数据。 数据到达后,我制作新的数据集,请原来我只是重绘mChartView生活。在这里提出我的问题。折线图重新绘制不重新生成图表只是在最后一个新的顶部。当然,距离记忆还有2-3分钟:(

这是我的代码:

class GetData extends AsyncTask<Void, String, Void> {

    private ArrayList<String> Alldata = new ArrayList<String>();
    public XYMultipleSeriesDataset datasetOut;
    public XYMultipleSeriesRenderer mRendererOut;

    @Override
    protected Void doInBackground(Void... unused) {

        Alldata.clear();
        Alldata = DataFromWeb.getChartDataNew("&name=XXX", "XXX");

        return (null);
    }

    @Override
    protected void onPostExecute(Void unused) {


        datasetOut = CCChart.getDataSet(getBaseContext(), Alldata);
        mRendererOut = CCChart.getRendererPortrait(getBaseContext());


        Log.d("Debug", "alldatasize: " + Alldata.size());
        Log.d("Debug", "dataset " + datasetOut.getSeriesCount() );

        if (mChartView != null) {
            mChartView.repaint();

            Log.v("CC_trace", "CCChartRepaint");

        } else {

            mChartView = ChartFactory.getLineChartView(getBaseContext(), datasetOut , mRendererOut);

                layout.addView(mChartView, new LayoutParams(
                        LayoutParams.WRAP_CONTENT, getHeight()));

                Log.v("CC_trace", "CCChartGenerate");   

        }




    }



} 

MAybe我没有打电话给重印():)

图表图片1

帮助......

1 个答案:

答案 0 :(得分:7)

在我的手中,我从不称呼重绘。我只是重新创建旧的

所以这样:

    @Override
    protected void onPostExecute(Void unused) {

    datasetOut = CCChart.getDataSet(getBaseContext(), Alldata);
    mRendererOut = CCChart.getRendererPortrait(getBaseContext());

    Log.d("Debug", "alldatasize: " + Alldata.size());
    Log.d("Debug", "dataset " + datasetOut.getSeriesCount() );

    mChartView = ChartFactory.getLineChartView(getBaseContext(), datasetOut , mRendererOut);

    layout.removeAllViews();
    layout.addView(mChartView, new LayoutParams(LayoutParams.WRAP_CONTENT, getHeight()));
    Log.v("CC_trace", "CCChartGenerate");   
}