6 Replies - 1862 Views - Last Post: 20 October 2011 - 11:14 AM Rate Topic: -----

#1 cs4ever  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • 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  Icon User is offline

  • D.I.C Lover
  • member icon

Reputation: 432
  • View blog
  • Posts: 1,020
  • Joined: 12-October 11

Re: drawing Pie Chart

Posted 20 October 2011 - 01:08 AM

Looks like fillArc() is what you want.

http://download.orac...t/Graphics.html
Was This Post Helpful? 0
  • +
  • -

#3 cs4ever  Icon User is offline

  • New D.I.C Head

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

Re: drawing Pie Chart

Posted 20 October 2011 - 01:44 AM

View PostSheph, on 20 October 2011 - 01:08 AM, said:

Looks like fillArc() is what you want.

http://download.orac...t/Graphics.html


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?
Was This Post Helpful? 0
  • +
  • -

#4 cs4ever  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • 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);

      }

Was This Post Helpful? 0
  • +
  • -

#5 cs4ever  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • 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? :helpsmilie:
Was This Post Helpful? 0
  • +
  • -

#6 cs4ever  Icon User is offline

  • New D.I.C Head

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

Re: drawing Pie Chart

Posted 20 October 2011 - 02:57 AM

View Postcs4ever, 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!!!
Was This Post Helpful? 0
  • +
  • -

#7 pbl  Icon User is offline

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

Reputation: 8316
  • View blog
  • Posts: 31,836
  • 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
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1