Go To ( http://adf.ly/20PrE )-)-) [android-developers] Problem with Canvas while draw large dataset

0 views
Skip to first unread message

to ngoc

unread,
Dec 6, 2011, 1:50:09 AM12/6/11
to Android Developers
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 android-d...@googlegroups.com
To unsubscribe from this group, send email to
android-develop...@googlegroups.com
For more options, visit this group at
http://groups.google.com/group/android-developers?hl=en

--
Go to Master Mind Home Base Income Website :-

http://adf.ly/20PrE

http://adf.ly/20PrE

Unsubscribe All Group Post :- http://j.gs/624707/unsubscribe

http://q.gs/624707/unsubscribe

Subscribe All Group Post :- http://j.gs/624707/subscribe

http://q.gs/624707/subscribe

Join Now Today (Paid Income) :-

http://adf.ly/20PrE

http://adf.ly/20PrE

http://adf.ly/20PrE

http://adf.ly/?id=624707

http://adf.ly/20PrE

http://adf.ly/20PrE

http://adf.ly/20PrE

http://adf.ly/20PrE

http://adf.ly/20PrE

http://adf.ly/20PrE

http://adf.ly/20PrE

http://adf.ly/20PrE

http://adf.ly/20PrE

http://adf.ly/20PrE

http://adf.ly/20PrE

http://adf.ly/20PrE

TreKing

unread,
Dec 6, 2011, 12:49:10 PM12/6/11
to android-d...@googlegroups.com
On Tue, Dec 6, 2011 at 12:50 AM, to ngoc <ngo...@citigovietnam.com> wrote:
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.

1 - Profile your code.
2 - Optimize your code.
3 - Profit.

-------------------------------------------------------------------------------------------------
TreKing - Chicago transit tracking app for Android-powered devices

Reply all
Reply to author
Forward
0 new messages