Grappa Graphviz点可视化问题和问题

我正在使用这个点代码进行测试:

digraph G { edge [dir=none]; p1 [shape=circle,style=filled,label="",height="0.01",width="0.01"]; q1 [shape=circle,style=filled,label="",height="0.01",width="0.01"]; q2 [shape=circle,style=filled,label="",height="0.01",width="0.01"]; q3 [shape=circle,style=filled,label="",height="0.01",width="0.01"]; {rank=same; father->p1; mother->p1}; {rank=same; q1->q2->q3}; {rank=same; son1; daughter1; daughter2}; p1->q2; q1->son1; q2->daughter1; q3->daughter2; } 

我创建Graph的Java代码如下:

 Graph graph = null; graph = program.getGraph(); JScrollPane jsp = new JScrollPane(); jsp.getViewport().setBackingStoreEnabled(true); GrappaPanel gp = new GrappaPanel(graph); gp.addGrappaListener(new GrappaAdapter()); gp.setScaleToFit(false); jsp.setViewportView(gp); 

输出是这样的: 链接

为什么Tree格式错误? 是否有可能让树从左到右显示?

您必须“询问”graphviz(任何工具,“点”,“neato”……)才能“格式化”图形,然后才能在GrappaPanel中显示它(以吸引人的方式)。 在构建GrappaPanel之前,您需要执行以下操作:

 String [] processArgs = {"dot"}; // You can use "neato" or whatever formatter you want Process formatProcess = Runtime.getRuntime().exec(processArgs, null, null); GrappaSupport.filterGraph(graph, formatProcess); formatProcess.getOutputStream().close(); 

GrappaSupport.filterGraph中的“图形”是你的图形。 之后,您的图表格式正确,您可以使用GrappaPanel查看它。 结果将比您在链接中发布的结果更令人愉快。

希望有所帮助,问候。

PS:为了使上述代码能够工作,你必须在路径中使用“dot”(或你使用的任何其他格式化程序),否则你需要为它提供可执行文件的完整路径。