Welcome to the Java Programming Forums


The professional, friendly Java community. 21,500 members and growing!


The Java Programming Forums are a community of Java programmers from all around the World. Our members have a wide range of skills and they all have one thing in common: A passion to learn and code Java. We invite beginner Java programmers right through to Java professionals to post here and share your knowledge. Become a part of the community, help others, expand your knowledge of Java and enjoy talking with like minded people. Registration is quick and best of all free. We look forward to meeting you.


>> REGISTER NOW TO START POSTING


Members have full access to the forums. Advertisements are removed for registered users.

Results 1 to 8 of 8

Thread: code to draw circles on a chart

  1. #1
    Junior Member
    Join Date
    Oct 2019
    Posts
    8
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default code to draw circles on a chart

    Good morning, I'm in the middle of a course project where I have to make a circle chart with a vector, spacing, color and radius as argument. But as you can see in the picture you are making squares instead of circles. Can you give me a hand?

    https://imgur.com/a/soSdV1u


    Thanks

  2. #2
    Super Moderator Norm's Avatar
    Join Date
    May 2010
    Location
    Eastern Florida
    Posts
    25,165
    Thanks
    65
    Thanked 2,725 Times in 2,675 Posts

    Default Re: code to draw circles on a chart

    Please post the code that you are working with that shows the problem.

    Be sure to wrap the code in code tags.
    If you don't understand my answer, don't ignore it, ask a question.

  3. #3
    Junior Member
    Join Date
    Oct 2019
    Posts
    8
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Re: code to draw circles on a chart

    https://imgur.com/a/GnjbeJZ

    here is the image of the result, I don't know why it's not making a perfect circle

  4. #4
    Super Moderator Norm's Avatar
    Join Date
    May 2010
    Location
    Eastern Florida
    Posts
    25,165
    Thanks
    65
    Thanked 2,725 Times in 2,675 Posts

    Default Re: code to draw circles on a chart

    Please copy and post here the code for the program you are having problems with. It should be complete so it can be compiled and executed for testing.
    Be sure to wrap the code in code tags.

    Do not post an image. Images are of no use because code can not be copied from them for testing.
    If you don't understand my answer, don't ignore it, ask a question.

  5. #5
    Junior Member
    Join Date
    Oct 2019
    Posts
    8
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Re: code to draw circles on a chart

    static ColorImage circle ( int[] v, int raio, int espaçamento, Color cor){
        	  ColorImage circle1 = new ColorImage ((v.length*(2*raio))+(v.length-1)*espaçamento, max(v)+raio+1);
        	  int x= raio+1;   
     
        	    for (int i = 0; i<v.length; i++) {
        	    	 setcircle1(circle1, v[i], raio,x , cor); 
        	    	 x=x+espaçamento+(raio*2)-1;
        	     }    
     
          return circle1;
     
    }              
     
     
     
     
     
     
    	          static void setcircle1(ColorImage circulo, int y, int r,int x, Color cor ){
    	        	 for(int i=-r;i<=r;i++)
    	        		 for(int j=-r;j<=r;j++)
    	        			 if( ((i*i)+(j*j))<=r*r){
    	        			 circulo.setColor(x+i,circulo.getHeight()-1-(y+j),cor);
     
     
    	         }
     
    	          }

  6. #6
    Super Moderator Norm's Avatar
    Join Date
    May 2010
    Location
    Eastern Florida
    Posts
    25,165
    Thanks
    65
    Thanked 2,725 Times in 2,675 Posts

    Default Re: code to draw circles on a chart

    How do I compile the code for testing? It is missing the import statements, the class definition, GUI components for showing the circles and the main method.

    Where is the paintComponent method for drawing? How does the code do any drawing? It needs a Graphics class reference and calls to its methods to do drawing.
    If you don't understand my answer, don't ignore it, ask a question.

  7. #7
    Junior Member
    Join Date
    Oct 2019
    Posts
    8
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Re: code to draw circles on a chart

    so that I can see the circles I use the perspective of this link: http: //pandionj.iscte-iul.pt.
    It is a learning software from my college.

  8. #8
    Super Moderator Norm's Avatar
    Join Date
    May 2010
    Location
    Eastern Florida
    Posts
    25,165
    Thanks
    65
    Thanked 2,725 Times in 2,675 Posts

    Default Re: code to draw circles on a chart

    Sorry, I do not know anything about the software you are using.

    If you have any questions about using the Java SE classes, please post them
    If you don't understand my answer, don't ignore it, ask a question.

Similar Threads

  1. using ActionListeners to draw circles
    By Scorks in forum AWT / Java Swing
    Replies: 4
    Last Post: November 21st, 2013, 06:11 AM
  2. Replies: 1
    Last Post: October 20th, 2013, 11:54 PM
  3. Replies: 2
    Last Post: May 27th, 2013, 10:33 AM
  4. Replies: 2
    Last Post: October 11th, 2011, 09:41 AM
  5. Change the random draw line here for a mouseListener draw
    By Panda23 in forum What's Wrong With My Code?
    Replies: 1
    Last Post: February 10th, 2011, 03:29 AM