I want to draw several pie chart by using a for loop, and the data is stored in an array (data[][][]
). When each chart draw is completed, I make the top and bottom plus 450 (top+=450; bottom+=450;
) to avoid the charts to overlap. But the result is that a pie chart moves to the bottom constantly. I try to add invalidate()
at the end of line but it doesn't work.
private String data[][][]=... //store some data
private float left=50,top=100,right=450, bottom=500;
public void onDraw(Canvas c) {
super.onDraw(c);
Paint paint = new Paint();
RectF rec;
for(int j=0;j<data.length;j++){
rec=new RectF(left,top,right,bottom);
//draw a pie chart
for (int i = 0; i < data[j].length; i++) {
float drawDegree = (float)Integer.parseInt(data[j][i][1])/100* 360f;
c.drawArc(rec, -90, drawDegree, true, paint);
}
top+=450;
bottom+=450;
}
}