Results 1 to 10 of 10

Thread: plot graph

  1. #1
    alaa is offline Member
    Join Date
    Apr 2011
    Posts
    8
    Rep Power
    0

    Default plot graph

    who can i plot graph in java to represint agraph for tree or other
    for example minmum tree in array like this

    {{0,1,-1,-1,5},{1,0,5,1,-1},{-1,8,0,1,-1},{-1,4,3,0,-1},{5,-1,-1,-1,0}}

    using line and node

  2. #2
    ra4king's Avatar
    ra4king is offline Senior Member
    Join Date
    Apr 2011
    Location
    Atlanta, Georgia, US
    Posts
    396
    Rep Power
    4

    Default

    Do you want a way to plot your data? How would you want that array to be in a tree? Please ask specific questions so we can help you better.

  3. #3
    alaa is offline Member
    Join Date
    Apr 2011
    Posts
    8
    Rep Power
    0

    Default

    I did not use drawing in Java and this is the first time I try to graph
    I want to represent the matrix containing the values ​​of using points, lines
    For example, if they contain 4 items means there are four points and values ​​in the matrix is the relationship between elements of the matrix represent the adjoint array for minmum spaning tree
    Attached Thumbnails Attached Thumbnails plot graph-images.jpg  

  4. #4
    ra4king's Avatar
    ra4king is offline Senior Member
    Join Date
    Apr 2011
    Location
    Atlanta, Georgia, US
    Posts
    396
    Rep Power
    4

    Default

    So you want to draw a tree like that in Java or you want widgets that do this for you?

  5. #5
    alaa is offline Member
    Join Date
    Apr 2011
    Posts
    8
    Rep Power
    0

    Default

    Weights are not important, but if zero or a negative one means that there is no relationship between the two factors
    Weights is that mean there is a relationship

    These first attempts
    XML Code:
            import java.awt.*;
    import java.awt.geom.*;
    import javax.swing.*;
       public class TestPanelDrawing extends JFrame {
       	
        public TestPanelDrawing() {
           add(new NewPanel());
         }
    
        public static void main(String[] args) {
          TestPanelDrawing frame = new TestPanelDrawing();
         frame.setTitle("TestPanelDrawing");
          frame.setLocationRelativeTo(null); // Center the frame
          frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
          frame.setSize(200, 300);
          frame.setVisible(true);
        }
      }
    
     class NewPanel extends JPanel {
     	public int  arr[][]={{0,1,2,-1},{1,0,-1,-1},{2,-1,0,3},{-1,-1,3,0}};
        protected void paintComponent(Graphics g) {
        	Graphics2D g2 = (Graphics2D)g;
          super.paintComponent(g);
          Point2D.Double point = new Point2D.Double(5,5);
          Ellipse2D.Double a=  new Ellipse2D.Double(6, 6, 20, 20);
          int x0=30;
          int x1=100;
          int y0=0;
          int y1=100;
          int x[]={x0,x1,x0,x1};
          int y[]={y0,y1,y0,y1};
        
             g2.fill(new Ellipse2D.Double(x0, y0, 15, 15));
             g2.fill(new Ellipse2D.Double(x0, y1, 15, 15));
               g2.fill(new Ellipse2D.Double(x1, y0, 15, 15));
               g2.fill(new Ellipse2D.Double(x1, y1, 15, 15));
         
         
           for(int i=0;i<4;i++){
           	
           g.drawString((char)A+i,30,15);
           	
           for (int j=0;j<4;j++){
           	
            g2.fill(new Ellipse2D.Double(x[i], y[j], 15, 15));
            if (arr[i][j]!=0&&arr[j][i]!=-1)
            g.drawLine(x[i], y[i], x[j], y[j]);	
           	
           }	 
           }
           
              }
      }

  6. #6
    ra4king's Avatar
    ra4king is offline Senior Member
    Join Date
    Apr 2011
    Location
    Atlanta, Georgia, US
    Posts
    396
    Rep Power
    4

    Default

    Sorry but I don't understand this whole tree system.

  7. #7
    alaa is offline Member
    Join Date
    Apr 2011
    Posts
    8
    Rep Power
    0

    Default

    I will make subject more easily
    I have a number of the Firtix A, B, C, D
    And a set of weights, for example AB 5 AC 8
    If the weight 0 or -1 means there is no path between the Firtix
    AA = 0

    Matrix representation of the paths between the elements
    I want to draw Graf represents these elements and the relationships between them
    I hope that the issue becomes clearer, I hope to help

  8. #8
    ra4king's Avatar
    ra4king is offline Senior Member
    Join Date
    Apr 2011
    Location
    Atlanta, Georgia, US
    Posts
    396
    Rep Power
    4

    Default

    Ah ok, I understand. So what questions do you have on this?

  9. #9
    alaa is offline Member
    Join Date
    Apr 2011
    Posts
    8
    Rep Power
    0

    Default

    i want to drow graph to represent this array for example

    public int arr[][]={{0,0,6,5,0,2,5},{0,0,-1,-1,0,2,3},{6,-1,0,3,3,2,3},{5,-1,3,0,5,2,1},{0,0,3,5,0,2,3},{2,2,2,2,2,0,7},{7,3, 5,1,0,7,0}};

    i drow it but i have some problem
    if you want i put my code

    XML Code:
       import java.util.ArrayList;
    import java.awt.*;
    import java.awt.geom.*;
    import javax.swing.*;
       public class TestPanelDrawing extends JFrame {
       		
        public TestPanelDrawing() {
           add(new NewPanel());
         }
    
        public static void main(String[] args) {
          TestPanelDrawing frame = new TestPanelDrawing();
          frame.setTitle("TestPanelDrawing");
          frame.setLocationRelativeTo(null); // Center the frame
          frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
          frame.setSize(600, 400);
          frame.setVisible(true);
        }
      }
    
     class NewPanel extends JPanel {
     public int  arr[][]={{0,0,6,5,0,2,5},{0,0,-1,-1,0,2,3},{6,-1,0,3,3,2,3},{5,-1,3,0,5,2,1},{0,0,3,5,0,2,3},{2,2,2,2,2,0,7},{7,3,5,1,0,7,0}};
       int 	size=7;
        protected void paintComponent(Graphics g) {
        		Font r = new Font("SansSerif", Font.BOLD, 16);
        	g.setFont(r);
        
        	if (size==4){
        
        	Graphics2D g2 = (Graphics2D)g;
          super.paintComponent(g);
          Point2D.Double point = new Point2D.Double(5,5);
         // Ellipse2D.Double a=  new Ellipse2D.Double(6, 6, 20, 20);
          int x0=30;
          int x1=150;
          int y0=20;
          int y1=150;
          int x[]={x0,x1,x0,x1};
          int y[]={y0,y1,y0,y1};
        	ArrayList<Ellipse2D.Double> vert = new ArrayList<Ellipse2D.Double>();
        	
        Ellipse2D.Double a=  new Ellipse2D.Double(x0+5, y0, 15, 15);
        Ellipse2D.Double b=  new Ellipse2D.Double(x0+5, y1, 15, 15);
        Ellipse2D.Double c=  new Ellipse2D.Double(x1+5, y0, 15, 15);
        Ellipse2D.Double d=  new Ellipse2D.Double(x1+5, y1, 15, 15);
        vert.add(a);
          vert.add(b);
          vert.add(c);
          vert.add(d);
          
        //g.drawLine((int)a.getX(), (int)a.getY(),(int) b.getX(),(int) b.getY());	
           	
        //for(int f=0;f<4;f++)
        	g.drawString(" A ",x0+15,y0);
        		g.drawString(" B ",x0+15,y1);
        			g.drawString(" C ",x1,y0);
        				g.drawString(" D ",x1+5,y1);
        	
        	
           vert.add(a);
          vert.add(b);
          vert.add(c);
          vert.add(d);
          
          
          	
             g2.fill(new Ellipse2D.Double(x0, y0, 15, 15));
             g2.fill(new Ellipse2D.Double(x0, y1, 15, 15));
            g2.fill(new Ellipse2D.Double(x1, y0, 15, 15));
            g2.fill(new Ellipse2D.Double(x1, y1, 15, 15));
         
         
           for(int i=0;i<4;i++){
          for (int j=0;j<4;j++){
          if (arr[i][j]!=0&&arr[j][i]!=-1)
         	g.drawLine((int)vert.get(i).getX(), (int)vert.get(i).getY(),(int)vert.get(j).getX(),(int)vert.get(j).getY());
           
           	
           }	 
           }
        	}
        	
        	
        	if (size==5){
        
        	Graphics2D g2 = (Graphics2D)g;
          super.paintComponent(g);
          Point2D.Double point = new Point2D.Double(5,5);
         // Ellipse2D.Double a=  new Ellipse2D.Double(6, 6, 20, 20);
          int x0=30;
          int x1=150;
          int x2=230;
          int y0=20;
          int y1=150;
          int y2=75;
          int x[]={x0,x1,x2};
          int y[]={y0,y1,y2};
        	ArrayList<Ellipse2D.Double> vert = new ArrayList<Ellipse2D.Double>();
        	
        Ellipse2D.Double a=  new Ellipse2D.Double(x0+5, y0, 15, 15);
        Ellipse2D.Double b=  new Ellipse2D.Double(x0+5, y1, 15, 15);
        Ellipse2D.Double c=  new Ellipse2D.Double(x1+5, y0, 15, 15);
        Ellipse2D.Double d=  new Ellipse2D.Double(x1+5, y1, 15, 15);
        Ellipse2D.Double e=  new Ellipse2D.Double(x2+5, y2, 15, 15);
       
        vert.add(a);
          vert.add(b);
          vert.add(c);
          vert.add(d);
          vert.add(e);
          
       // g.drawLine((int)a.getX(), (int)a.getY(),(int) b.getX(),(int) b.getY());	
           	
       // for(int f=0;f<5;f++)
        	g.drawString(" A ",x0+15,y0);
        		g.drawString(" B ",x0+15,y1);
        			g.drawString(" C ",x1,y0);
        				g.drawString(" D ",x1+5,y1);
        	              g.drawString(" E ",x2+5,y2);
        	
          
          
          	
             g2.fill(new Ellipse2D.Double(x0, y0, 15, 15));
             g2.fill(new Ellipse2D.Double(x0, y1, 15, 15));
            g2.fill(new Ellipse2D.Double(x1, y0, 15, 15));
            g2.fill(new Ellipse2D.Double(x1, y1, 15, 15));
            g2.fill(new Ellipse2D.Double(x2, y2, 15, 15));
         
           for(int i=0;i<5;i++){
          for (int j=0;j<5;j++){
          if (arr[i][j]!=0&&arr[j][i]!=-1)
         	g.drawLine((int)vert.get(i).getX(), (int)vert.get(i).getY(),(int)vert.get(j).getX(),(int)vert.get(j).getY());
           
           	
           }	 
           }
        	}
        	
          //////////////
          
          	if (size==6){
        
        	Graphics2D g2 = (Graphics2D)g;
          super.paintComponent(g);
          Point2D.Double point = new Point2D.Double(5,5);
         // Ellipse2D.Double a=  new Ellipse2D.Double(6, 6, 20, 20);
          int x0=30;
          int x1=150;
          int x2=300;
          int y0=20;
          int y1=150;
          
          int x[]={x0,x1,x2};
          int y[]={y0,y1};
        	ArrayList<Ellipse2D.Double> vert = new ArrayList<Ellipse2D.Double>();
        	
        Ellipse2D.Double a=  new Ellipse2D.Double(x0+5, y0, 15, 15);
        Ellipse2D.Double b=  new Ellipse2D.Double(x0+5, y1, 15, 15);
        Ellipse2D.Double c=  new Ellipse2D.Double(x1+5, y0, 15, 15);
        Ellipse2D.Double d=  new Ellipse2D.Double(x1+5, y1, 15, 15);
        Ellipse2D.Double e=  new Ellipse2D.Double(x2+5, y0, 15, 15);
        Ellipse2D.Double f=  new Ellipse2D.Double(x2+5, y1, 15, 15);
        vert.add(a);
          vert.add(b);
          vert.add(c);
          vert.add(d);
          vert.add(e);
          vert.add(f);
       // g.drawLine((int)a.getX(), (int)a.getY(),(int) b.getX(),(int) b.getY());	
           	
       // for(int f=0;f<4;f++)
        	g.drawString(" A ",x0+15,y0);
        		g.drawString(" B ",x0+15,y1);
        			g.drawString(" C ",x1,y0);
        				g.drawString(" D ",x1+5,y1);
        	              g.drawString(" E ",x2+5,y0);
        	               g.drawString(" F ",x2+5,y1);
          
          
          	
             g2.fill(new Ellipse2D.Double(x0, y0, 15, 15));
             g2.fill(new Ellipse2D.Double(x0, y1, 15, 15));
            g2.fill(new Ellipse2D.Double(x1, y0, 15, 15));
            g2.fill(new Ellipse2D.Double(x1, y1, 15, 15));
            g2.fill(new Ellipse2D.Double(x2, y0, 15, 15));
           g2.fill(new Ellipse2D.Double(x2, y1, 15, 15));
           
           for(int i=0;i<6;i++){
          for (int j=0;j<6;j++){
          if (arr[i][j]!=0&&arr[j][i]!=-1)
         	g.drawLine((int)vert.get(i).getX(), (int)vert.get(i).getY(),(int)vert.get(j).getX(),(int)vert.get(j).getY());
           
           	
           }	 
           }
        	}
          
          /////////
          	if (size==7){
        
        	Graphics2D g2 = (Graphics2D)g;
          super.paintComponent(g);
          Point2D.Double point = new Point2D.Double(5,5);
         // Ellipse2D.Double a=  new Ellipse2D.Double(6, 6, 20, 20);
          int x0=30;
          int x1=150;
          int x2=300;
          int x4=450;
          int y0=20;
          int y1=150;
          int y2=75;
          
          int x[]={x0,x1,x2,x4};
          int y[]={y0,y1,y2};
        	ArrayList<Ellipse2D.Double> vert = new ArrayList<Ellipse2D.Double>();
        	
        Ellipse2D.Double a=  new Ellipse2D.Double(x0+5, y0, 15, 15);
        Ellipse2D.Double b=  new Ellipse2D.Double(x0+5, y1, 15, 15);
        Ellipse2D.Double c=  new Ellipse2D.Double(x1+5, y0, 15, 15);
        Ellipse2D.Double d=  new Ellipse2D.Double(x1+5, y1, 15, 15);
        Ellipse2D.Double e=  new Ellipse2D.Double(x2+5, y0, 15, 15);
        Ellipse2D.Double f=  new Ellipse2D.Double(x2+5, y1, 15, 15);
        Ellipse2D.Double t=  new Ellipse2D.Double(x2+5, y1, 15, 15);
        
        vert.add(a);
          vert.add(b);
          vert.add(c);
          vert.add(d);
          vert.add(e);
          vert.add(f);
          vert.add(t);
       // g.drawLine((int)a.getX(), (int)a.getY(),(int) b.getX(),(int) b.getY());	
           	
       // for(int f=0;f<4;f++)
        	g.drawString(" A ",x0+15,y0);
        		g.drawString(" B ",x0+15,y1);
        			g.drawString(" C ",x1,y0);
        				g.drawString(" D ",x1+5,y1);
        	              g.drawString(" E ",x2+5,y0);
        	               g.drawString(" F ",x2+5,y1);
                            g.drawString(" G ",x4+5,y2);
          
          	
             g2.fill(new Ellipse2D.Double(x0, y0, 15, 15));
             g2.fill(new Ellipse2D.Double(x0, y1, 15, 15));
            g2.fill(new Ellipse2D.Double(x1, y0, 15, 15));
            g2.fill(new Ellipse2D.Double(x1, y1, 15, 15));
            g2.fill(new Ellipse2D.Double(x2, y0, 15, 15));
           g2.fill(new Ellipse2D.Double(x2, y1, 15, 15));
           g2.fill(new Ellipse2D.Double(x4, y2, 15, 15));
           
           for(int i=0;i<7;i++){
          for (int j=0;j<7;j++){
          if (arr[i][j]!=0&&arr[j][i]!=-1)
         	g.drawLine((int)vert.get(i).getX(), (int)vert.get(i).getY(),(int)vert.get(j).getX(),(int)vert.get(j).getY());
           
           	
           }	 
           }
        	}
          
        }
      }

  10. #10
    ra4king's Avatar
    ra4king is offline Senior Member
    Join Date
    Apr 2011
    Location
    Atlanta, Georgia, US
    Posts
    396
    Rep Power
    4

Similar Threads

  1. Unable to re-plot the graph!
    By Y. Progammer in forum New To Java
    Replies: 22
    Last Post: 02-20-2010, 11:38 PM
  2. How to plot a graph for two sets of variables....
    By Megatron in forum New To Java
    Replies: 9
    Last Post: 04-20-2009, 10:20 PM
  3. i want plot realtime graph in java
    By santhosh_el in forum New To Java
    Replies: 3
    Last Post: 02-26-2009, 09:32 AM
  4. How to plot a dot graph
    By Manfizy in forum Java 2D
    Replies: 3
    Last Post: 01-28-2009, 03:57 PM
  5. Need Help for Dot Plot Graph
    By BHCluster in forum Java 2D
    Replies: 5
    Last Post: 04-15-2008, 03:54 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
  •