这是我的代码,输出不是分层树的形式
public class Simple {
public static void main(String[] args) {
Graph graph = new SingleGraph("Test");
Viewer viewer = graph.display(false);
HierarchicalLayout hl = new HierarchicalLayout();
viewer.enableAutoLayout(hl);
graph.setStrict(false);
graph.setAutoCreate(false);
graph.addNode("A" );
graph.addNode("B" );
graph.addNode("C" );
graph.addNode("D");
graph.addNode("E");
graph.getNode("A").addAttribute("ui.label", "A");
graph.getNode("B").addAttribute("ui.label", "B");
graph.addEdge("A-B", "A", "B",true);
graph.addEdge("A-C", "A", "C",true);
graph.addEdge("B-D", "B", "D",true);
graph.addEdge("B-E", "B", "E",true);
即使我使用分层布局,节点也是随机放置的。
我正在尝试绘制一棵树,如下图所示:
.