# drawing Pie Chart

Page 1 of 1

## 6 Replies - 3577 Views - Last Post: 20 October 2011 - 11:14 AMRate Topic: //<![CDATA[ rating = new ipb.rating( 'topic_rate_', { url: 'http://www.dreamincode.net/forums/index.php?app=forums&module=ajax&section=topics&do=rateTopic&t=252140&amp;s=283a6fd4a17e4eb31596a59f002624ed&md5check=' + ipb.vars['secure_hash'], cur_rating: 0, rated: 0, allow_rate: 0, multi_rate: 1, show_rate_text: true } ); //]]>

### #1 cs4ever

Reputation: 0
• Posts: 5
• Joined: 20-October 11

# drawing Pie Chart

Posted 20 October 2011 - 12:56 AM

Dear all,
Hope you are fine.
I want you to help me how to draw pie chart in java?
I draw circle
```g.fillOval(counerX - diameter  , counterY - diameter , diameter * 2 ,  diameter * 2 );
```

But I don't know How to make partions!!
Is This A Good Question/Topic? 0

## Replies To: drawing Pie Chart

### #2 Sheph

• D.I.C Lover

Reputation: 447
• Posts: 1,032
• Joined: 12-October 11

## Re: drawing Pie Chart

Posted 20 October 2011 - 01:08 AM

Looks like fillArc() is what you want.

### #3 cs4ever

Reputation: 0
• Posts: 5
• Joined: 20-October 11

## Re: drawing Pie Chart

Posted 20 October 2011 - 01:44 AM

Sheph, on 20 October 2011 - 01:08 AM, said:

Looks like fillArc() is what you want.

So now the hight ,the width, x and y axes should be same as for the circle.
is it correct that what I understand?

if i use random number, how I put it as start angle? and how I determine arcAngle?

### #4 cs4ever

Reputation: 0
• Posts: 5
• Joined: 20-October 11

## Re: drawing Pie Chart

Posted 20 October 2011 - 02:00 AM

I try to do it. It works But I have proplem to specify x and y!!
```for (int i = 0 ; i < NumOfPartioins ; i ++){
g.setColor(new Color((int)(Math.random()*256),(int)(Math.random()*256),(int)(Math.random()*256)));
g.fillArc(counerX - diameter, counterY - diameter, diameter * 2 , diameter * 2, 0, RandNum);

}
```

### #5 cs4ever

Reputation: 0
• Posts: 5
• Joined: 20-October 11

## Re: drawing Pie Chart

Posted 20 October 2011 - 02:17 AM

Another thing is that which method will help me to rotat any shape?

### #6 cs4ever

Reputation: 0
• Posts: 5
• Joined: 20-October 11

## Re: drawing Pie Chart

Posted 20 October 2011 - 02:57 AM

cs4ever, on 20 October 2011 - 02:00 AM, said:

I try to do it. It works But I have proplem to specify x and y!!
```for (int i = 0 ; i < NumOfPartioins ; i ++){
g.setColor(new Color((int)(Math.random()*256),(int)(Math.random()*256),(int)(Math.random()*256)));
g.fillArc(counerX - diameter, counterY - diameter, diameter * 2 , diameter * 2, 0, RandNum);

}
```

I mean with starting angle and arc angle!!!

### #7 pbl

• There is nothing you can't do with a JTable

Reputation: 8369
• Posts: 31,956
• Joined: 06-March 08

## Re: drawing Pie Chart

Posted 20 October 2011 - 11:14 AM

Starting angle ? you can pick up the one you want
The arc angle would be 360 degrees/the weight of the slice you want to draw. Simple math

If you have 4 slices with value 100 50 25 25
first one will be 180 degrees the second 90 and the two last ones 45