Dimension sz = getSize();
int w = sz.width, h = sz.width;
if (title != null)
g.drawString(title, w/10, (int)(h*.9));
if (data == null || data.length == 0) {
g.drawOval(0, 0, w, h);
g.drawString("Please provide some data!", w/10, h/2);
return;
}
int total = 0;
int angle = 0;
int rad = 0; // "radians" (actually degrees) to draw
int colNum = 0;
for (int i=0; i<data.length; i++)
total += data[i].value;
for (int i=0; i<data.length; i++) {
rad = (int)(CIRCLE * ((float)data[i].value / (float)total));
// System.out.println("data: "+data[i].name+";"+data[i].value+
// ",rad="+rad);
g.setColor(colors[colNum++]);
colNum%=colors.length; // keep it in bounds
g.fillArc(0, 0, w, h, angle, rad);
angle += rad;
}