Hi everybody,

I have a problem : I wan't to draw Chart(live chart) with large
dataset. I used canvas for my program, but when scroll my view ,
screen not smooth. I think my dataset so large (40000 point in chart).
Please help me fix problem.

This is my code :

    protected void onDraw(Canvas canvas) {

        drawGraph(canvas, (int)left);
        drawData(canvas,(int)left);
    }

    public void drawData(Canvas canvas, int left)
    {
        Paint p3 = new Paint();
        p3.setColor(Color.GREEN);
        int k = 45;

        if(av != null)
        {
                for(int j = 0 ;j <av.length - 1;j++)
                {
                        float mx = k;
                        float my =(float) ( (15+180)/2 - av[j]*16.5);

                        float nx = k+30;
                        float ny = (float)((15+180)/2 - av[j+1]*16.5);

                        canvas.drawLine(mx-left, my, nx-left, ny, p3);
                        k = k+30;
                }
        }
    }

    public void drawGraph(Canvas canvas,int left)
    {
        paint.setColor(Color.RED);
        p1.setColor(Color.parseColor("#343434"));
        DashPathEffect dashPath = new DashPathEffect(new float[]
{5,10}, 0);
        p1.setPathEffect(dashPath);
        p1.setStrokeWidth(1);

        Paint p2 = new Paint();
        p2.setColor(Color.parseColor("#343434"));

        Canvas c = new Canvas();


        canvas.drawLine(15, 15, 15, 180, paint);
        canvas.drawLine(15, (15+180)/2, 320*500, (15+180)/2, paint);
        canvas.drawText("5", 0, 20, paint);
        canvas.drawText("0",0,100,paint);
        canvas.drawText("-5", 0, 180, paint);
        canvas.drawLine(15, 15, 320*500, 15, p2);
        canvas.drawLine(15, 180, 320*500, 15, p2);
        canvas.drawText("3", 0, (180-15)/5 +15, paint);
        canvas.drawLine(15, (180-15)/5 +15, 320*500, (180-15)/5 +15,
p2);
        canvas.drawText("1", 0, (180-15)*2/5 +15, paint);
        canvas.drawLine(15, 2*(180-15)/5+15, 320*500, 2*(180-15)/5
+15, p2);
        canvas.drawText("-1",0, (180-15)*3/5 +15 +5, paint);
        canvas.drawLine(15,(180-15)*3/5 +15,320*500,(180-15)*3/5 +
15,p2);
        canvas.drawText("-3", 0, (180-15)*4/5 +15+5,paint);
        canvas.drawLine(15, (180-15)*4/5 +15, 320*500, (180-15)*4/5
+15, p2);

        int n = 1;
        for(int i= 45; i<320*100; i = i +30)
        {
                canvas.drawLine(i-left, 13,i-left, 190, p1);
                canvas.drawText(Integer.toString(n),i -left, 200, p2);
                n++;
        }


    }

-- 
You received this message because you are subscribed to the Google
Groups "Android Developers" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to
[email protected]
For more options, visit this group at
http://groups.google.com/group/android-developers?hl=en

Reply via email to