1

I am facing with a werid problem. The demos run well, but in my own app, If I switched to another app, and then switched back, there would be an small duplicated chart on the left bottom.

The chart in my app will be updated(add new (x,y) and repaint) at intervals.

Attached are the original image and image after switched back.

I suspect there are some problems with my onResume() method.

@Override
protected void onResume() {
    super.onResume();

    if (mChartView == null) {
        LinearLayout layout = (LinearLayout) findViewById(R.id.linearlayout_chart);
        mChartView = ChartFactory.getLineChartView(this, mDataSet, mRenderer);
        mRenderer.setClickEnabled(true);
        mRenderer.setSelectableBuffer(100);


        mChartView.setOnClickListener(new OnClickListener() {
            public void onClick(View v) {

            }
        });
        mChartView.setOnLongClickListener(new OnLongClickListener() {
             public boolean onLongClick(View v) {
                 return false;
             }
         });
         mChartView.addZoomListener(new ZoomListener() {

             public void zoomApplied(ZoomEvent e) {
             }
             public void zoomReset() {
             }
         }, true, true);

         mChartView.addPanListener(new PanListener() {
             public void panApplied() {}
         });

         layout.addView(mChartView, new LayoutParams(LayoutParams.MATCH_PARENT, LayoutParams.MATCH_PARENT));
    }

    mChartView.repaint();

}

I cannot figure out why did this happen, does anyone have the same problem?

The normal chart: normal chart

After switched back from another app: enter image description here

Android 3.2 (API Level 13) AChartEngine version 0.7.0 Asus EEE pad

Wenshan
  • 690
  • 6
  • 13
  • Hi, I'm facing the same problem right now, Can you tell me how you solved it?? Thank you! – Lucia Mar 12 '12 at 13:35

1 Answers1

0

If you are just adding new data, you should just fill dataset with new data and repaint the graph. You create graph onCreate and just refresh it when you add new data.

look at: creating timechar.

Code for refresh - for example in link should be:

private void updateData(List<Point> data) {
        int size= data.size();
        int lastsize = time_series.getItemCount();
        if (lastsize < size) {
        //add new data
        for (int i = lastsize ; i < size; i++) {
            try {
                Point p = pointslist.get(i);
                series.add(p.x,p.y);
            } catch (Exception e) {
                e.printStackTrace();
            }
        }

        mChartView.repaint();
    }
    }

Here you add only new points from your list. I had value object here called Point:

public class Point {
       public Date x;
       public double y;

       public Point() {
         super();
       };
}

You can use your own object or just 2D array.

Hope it helps, Toni

Community
  • 1
  • 1
toni
  • 361
  • 7
  • 19
  • Thank you for your reply. Probably I didn't describe the problem clearly. My app can update the graph, the problem is if I switch to another app, and then switch back, there will be a smaller copy of the graph on the left hand side. – Wenshan Feb 08 '12 at 01:26
  • The app keep updating when I switch to other apps. And when I switch back, after one update, the small image will disappear. – Wenshan Feb 08 '12 at 02:22