Java Grappa Graphviz点可视化问题和问题

Java Grappa Graphviz点可视化问题和问题,java,graphviz,dot,graph-layout,family-tree,Java,Graphviz,Dot,Graph Layout,Family Tree,我正在使用此dot代码进行测试: 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"];

我正在使用此dot代码进行测试:

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;
}
我创建图形的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);
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();
输出如下:

为什么树的格式如此错误?有没有可能让树从左到右显示

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

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);
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();
其中grappassupport.filterGraph中的“graph”是您的图形。之后,图形的格式正确,您可以使用Grappanel查看它。结果将比您在链接中发布的内容更令人愉快

希望对你有所帮助,问候你

PS:为了让上面的代码正常工作,您必须在路径中有“点”(或您使用的任何其他格式化程序),否则您需要为其提供可执行文件的完整路径