以下是我遇到的问题的一个简单示例。在我的真实数据中,我有许多来自数据存储的“链接”,其格式为
entityA_ID, entityB_ID, Link_type
,例如
a,b,"link"
a,c,"link"
b,d,"link"
因此,entityA_ID或entityB_ID字段具有“重复”,因为许多内容都链接到同一节点。
如何制作“世界”!实体独特? 这就是我在运行它时看到的内容(实际上一个无向图表会很好):
这就是我想要的,因为我只想要一个世界!实体(借口鸡刮):
这是代码
import com.mxgraph.layout.hierarchical.mxHierarchicalLayout;
import com.mxgraph.layout.mxGraphLayout;
import javax.swing.JFrame;
import com.mxgraph.swing.mxGraphComponent;
import com.mxgraph.view.mxGraph;
import java.util.HashSet;
import java.util.Set;
import java.util.logging.Level;
import java.util.logging.Logger;
public class HelloWorld1 extends JFrame {
/**
*
*/
private static final long serialVersionUID = -2707712944901661771L;
public HelloWorld1() {
super("Hello, World!");
mxGraph graph = new mxGraph();
Object parent = graph.getDefaultParent();
mxGraphLayout layout = new mxHierarchicalLayout(graph);
graph.getModel().beginUpdate();
Set<String> inserted = new HashSet<>();
try {
Object v1 = graph.insertVertex(parent, null, "Hello", 20, 20, 80, 30);
Object v2 = graph.insertVertex(parent, null, "World!", 240, 150, 80, 30);
Object v3 = graph.insertVertex(parent, null, "World!", 240, 150, 80, 30);
graph.insertEdge(parent, null, "Edge", v1, v2);
graph.insertEdge(parent, null, "Edge 2", v1, v3);
graph.insertEdge(parent, null, "Edge 3", v2, v3);
} catch (Exception ex) {
Logger.getLogger(HelloWorld1.class.getName()).log(Level.SEVERE, null, ex);
} finally {
layout.execute(parent);
graph.getModel().endUpdate();
}
mxGraphComponent graphComponent = new mxGraphComponent(graph);
getContentPane().add(graphComponent);
}
public static void main(String[] args) {
HelloWorld1 frame = new HelloWorld1();
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
frame.setSize(400, 320);
frame.setVisible(true);
}
}
这是我的pom参考
<dependency>
<groupId>com.mxgraph</groupId>
<artifactId>jgraphx</artifactId>
<version>3.5.1.4</version>
</dependency>