Results 1 to 10 of 10
Thread: plot graph
- 04-13-2011, 10:11 PM #1
Member
- Join Date
- Apr 2011
- Posts
- 8
- Rep Power
- 0
- 04-14-2011, 12:34 AM #2
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.
- 04-14-2011, 02:21 PM #3
Member
- Join Date
- Apr 2011
- Posts
- 8
- Rep Power
- 0
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
- 04-14-2011, 06:32 PM #4
So you want to draw a tree like that in Java or you want widgets that do this for you?
- 04-14-2011, 06:37 PM #5
Member
- Join Date
- Apr 2011
- Posts
- 8
- Rep Power
- 0
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]); } } } }
- 04-14-2011, 06:41 PM #6
- 04-14-2011, 06:49 PM #7
Member
- Join Date
- Apr 2011
- Posts
- 8
- Rep Power
- 0
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
- 04-14-2011, 11:08 PM #8
- 04-15-2011, 08:44 AM #9
Member
- Join Date
- Apr 2011
- Posts
- 8
- Rep Power
- 0
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()); } } } } }
- 04-15-2011, 09:13 PM #10
Similar Threads
-
Unable to re-plot the graph!
By Y. Progammer in forum New To JavaReplies: 22Last Post: 02-20-2010, 10:38 PM -
How to plot a graph for two sets of variables....
By Megatron in forum New To JavaReplies: 9Last Post: 04-20-2009, 09:20 PM -
i want plot realtime graph in java
By santhosh_el in forum New To JavaReplies: 3Last Post: 02-26-2009, 08:32 AM -
How to plot a dot graph
By Manfizy in forum Java 2DReplies: 3Last Post: 01-28-2009, 02:57 PM -
Need Help for Dot Plot Graph
By BHCluster in forum Java 2DReplies: 5Last Post: 04-15-2008, 02:54 PM


LinkBack URL
About LinkBacks
Reply With Quote
Bookmarks