我正在使用GraphStream Library for java。但我在这里面临一个问题。 我试图从数据库中查询10,000列有2列的记录。图形为每行创建2个节点和一个边。 但是当我尝试运行程序时,图表看起来非常复杂。见下图。
这是我的代码:
public class GraphExplore {
static Connection conn2;
static String result, result2;
static int totalRows, i;
public static void main(String args[]) throws SQLException {
EventQueue.invokeLater(new Runnable() {
public void run() {
try {
showData();
} catch (SQLException e) {
e.printStackTrace();
}
}
});
}
private static void showData() throws SQLException {
JFrame frame = new JFrame("GRAPH");
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
@SuppressWarnings("serial")
JPanel panel = new JPanel(new GridLayout()) {
@Override
public Dimension getPreferredSize() {
return new Dimension(640, 480);
}
};
panel.setBorder(BorderFactory.createLineBorder(Color.blue, 5));
Graph graph = new SingleGraph("Tutorial", false, true);
try {
Class.forName("org.h2.Driver");
conn2 = DriverManager.getConnection("jdbc:h2:file:G:/hs_data/h2_db/test", "sa", "sa");
} catch (Exception e) {
e.printStackTrace();
}
Statement stmt2 = conn2.createStatement();
ResultSet rs = stmt2.executeQuery("SELECT count(*) FROM cdr");
while (rs.next()) {
totalRows = rs.getInt(1);
}
ResultSet rs2 = stmt2.executeQuery("SELECT ANUMBER,BNUMBER FROM CDR LIMIT 1000");
while (rs2.next()) {
result = rs2.getString("ANUMBER");
result2 = rs2.getString("BNUMBER");
graph.addNode(result);
graph.addNode(result2);
for (i = 0; i < 1000; i++)
graph.addEdge("string" + i, result, result2);
}
graph.setAutoCreate(true);
graph.setStrict(false);
Viewer viewer = new Viewer(graph, Viewer.ThreadingModel.GRAPH_IN_GUI_THREAD);
ViewPanel viewPanel = viewer.addDefaultView(false);
viewer.enableAutoLayout();
panel.add(viewPanel);
frame.add(panel);
frame.pack();
frame.setLocationRelativeTo(null);
frame.setVisible(true);
for (Node node : graph) {
node.addAttribute("ui.label", node.getId());
}
// graph.addAttribute("ui.stylesheet", "graph { fill-color: red; }");text-mode:
// hidden;
graph.addAttribute("ui.stylesheet", "node {size:12px;fill-color:#ff0000;}");
graph.addAttribute("ui.stylesheet", "edge { shape:angle ;fill-color:#222;}");
}
}
有谁能告诉我,如何为这张图提供更好的可视化效果。或者我必须使用其他一些图表。我使用的是非常基本的example GraphStream。