Results 1 to 2 of 2
  1. #1
    shruti is offline Member
    Join Date
    Jul 2009
    Posts
    7
    Rep Power
    0

    Default plot some values as a circle with different colors

    well,i have a list of values.these values basically appear as points on a circle .the plotting part is quite easy but my problem is that i need to make these points appear in different colors according to their value.

    for example,i have values 12,14,18,12.5,20,7,5.6,7.9,10,11.5

    these values appear as points on the color but depending on the value.
    i.e points whose values are below 10 appaer as red,between 10-15 appear as green and above 15 appear as blue.

    i have written this code but i don't know how can i incorporate the color in this program.please help

    Java Code:
    class plotter extends JComponent
    {
    	
    	 final double  X_CENTER = 400;
        	final double Y_CENTER = 300;
    	 double x,y;
    	public void paint(Graphics g)
    	{
    
    	mpplot obj=new mpplot();
    	 Graphics2D g2=(Graphics2D)g;
    	double	radius4= 150.0f;
    	int numpix4=10;//no of points(values) that i need to plot as a circle
    	double mparr[]=obj.array1;
    	double angle4,anginc4;
    
    	 anginc4 = (double) (2.0 * Math.PI / numpix4);
    	
    	
    	for (angle4 = 0.0f; angle4 < 2.0 * Math.PI; angle4 += anginc4)
            {  
                x = X_CENTER + (int) (radius4 * Math.cos(angle4));
                y = Y_CENTER + (int) (radius4 * Math.sin(angle4));
    	   g2.setStroke(new BasicStroke(5.0f));
    	   	
                g2.draw(new Line2D.Double(x, y,x, y));
        
            }
    	
         
    	}//end paint
    	
    
    
    
    
    }//end class

  2. #2
    dswastik is offline Senior Member
    Join Date
    Dec 2008
    Location
    Kolkata
    Posts
    282
    Rep Power
    6

    Default

    Java Code:
    for (angle4 = 0.0f; angle4 < 2.0 * Math.PI; angle4 += anginc4)
            {  
                x = X_CENTER + (int) (radius4 * Math.cos(angle4));
                y = Y_CENTER + (int) (radius4 * Math.sin(angle4));
    	   g2.setStroke(new BasicStroke(5.0f));
    	    //put a check here
                /* 
                     if(plottingPointValue>=1 && plottingPointValue<=15){
                         g2.setColor(Color.RED);
                     }
                */ 	
                g2.draw(new Line2D.Double(x, y,x, y));
        
            }

Similar Threads

  1. drawing a dashed circle
    By Alarmmy in forum SWT / JFace
    Replies: 0
    Last Post: 07-13-2009, 09:46 AM
  2. How to write numbers around a circle
    By pheonix in forum New To Java
    Replies: 8
    Last Post: 06-11-2009, 10:20 AM
  3. Generate numbers around a circle?
    By pheonix in forum New To Java
    Replies: 4
    Last Post: 06-05-2009, 05:08 PM
  4. java program help. find the radius of a circle
    By megironi in forum New To Java
    Replies: 1
    Last Post: 03-27-2009, 07:09 AM
  5. In which circle is the Point lying?
    By nidhirastogi in forum New To Java
    Replies: 1
    Last Post: 07-02-2008, 11:12 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •