2011-08-27 27 views
3

我用這點代碼爲我的測試:格拉帕的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; 
} 

我的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); 

的輸出這個:Link

爲什麼Tree格式錯了?是否有可能讓樹顯示從左到右?

回答

1

您必須「問」graphviz(任何工具,「dot」,「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查看它。結果會比您在鏈接中發佈的內容更令人愉快。

希望有幫助,問候。爲了使上述代碼正常工作,必須使用「dot」(或任何其他格式化程序)在路徑中,否則您需要爲其提供可執行文件的完整路徑。