1

i have parsed a raw xml file and fetched many vertices and the edges that i would need, but i cant able to actually plot it... i.e, suppose i have the hashmap containing the folowing key-->value pair... the HashMap is of following type pair "String,ArrayList of String"

A--------->[B, C]

B--------->[H, J]

Y--------->[Z]

for the above contents, i want a graph similar to this: enter image description here i can't able to find the solution for this anywhere.

Christophe Roussy
  • 16,299
  • 4
  • 85
  • 85
SpaceyBot
  • 482
  • 1
  • 4
  • 20

1 Answers1

1

Try using the dot language, it is a simple text format.

But there is even a pure Java lib for it: https://github.com/nidi3/graphviz-java

import static guru.nidi.graphviz.model.Factory.*
Graph g = graph("example1").directed().with(node("a").link(node("b")));
Graphviz.fromGraph(g).width(200).render(Format.PNG).toFile(new File("example/ex1.png"));

Adapt this example ... and it should work.

There are other solutions see:

Java graph library for dynamic visualisation

In the worst case just generate dot text and render outside of java using graphviz.

Christophe Roussy
  • 16,299
  • 4
  • 85
  • 85
  • How exactly? i mean i tried your method, but its throwing NoSuchElementException.. Graph g = null; for(String ke : domParser.hashMap.keySet()) { Iterator it = domParser.hashMap.get(ke).iterator(); while(it.hasNext()) { graph.addEdge(ke, it.next().toString()); g = graph("ex").directed().with(node(ke).link(node(it.next().toString()))); } } try { Graphviz.fromGraph(g).width(200).render(Format.PNG).toFile(new File("example/ex1.png")); } catch (IOException e) { e.printStackTrace(); } – SpaceyBot Mar 28 '18 at 13:45
  • I dont why the formatting doesnt work..sorry for that – SpaceyBot Mar 28 '18 at 13:46
  • See the docs on the graphviz-java site, if it does not work, try other links. – Christophe Roussy Mar 28 '18 at 14:17