在Java中可视化图表

huangapple go评论85阅读模式
英文:

Visualize graphs in java

问题

I'm currently working on a university project to implement simple graph algorithms in java
(https://en.wikipedia.org/wiki/Graph_(discrete_mathematics))
and I'm struggling to find a simple solution to export my created graphs into an image file (i.e. .png)

I already looked at tools like GraphViz and GraphStream, but they seem to focus more on visualizing their own code to create graphs.

Has anybody knowledge of a simple library or maybe even external tool which can interpret my generated output in a image file? If possible something lightweight and easy to implement.

[My code] ---> [Output] ---> [What I'm in search of] ---> [Image File]

英文:

I'm currently working on a university project to implement simple graph algorithms in java
(https://en.wikipedia.org/wiki/Graph_(discrete_mathematics))
and I'm struggling to find a simple solution to export my created graphs into a image file (i.e. .png)

I already looked at tools like GraphViz and GraphStream, but they seem to focus more on visualizing their own code to create graphs.

Has anybody knowledge of a simple library or maybe even external tool which can interpret my generated output in a image file? If possible something lightweight and easy to implement.

[My code] ---> [Output] ---> [What I'm in search of] ---> [Image File]

答案1

得分: 0

如果您使用Graphviz Dot语言生成输出,您可以使用dotty将其可视化,并使用dot程序将其导出为PNG或其他图像格式。Dot语言非常简单,例如以下是一个带有3个节点的有向图,形成一个循环,并在第三个节点中有一条自环边。

digraph {
A -> B
B -> C
C -> A
C -> C
}

以下是在dotty中的渲染效果:

在Java中可视化图表

英文:

If you generate output in the Graphviz Dot language, you can visualize it with dotty and export to PNG or other image formats with the dot program. The Dot language is very simple, for example here's a directed graph with 3 nodes making a cycle, and a self-edge in the third node.

digraph {
A -> B
B -> C
C -> A
C -> C
}

This is how it's rendered in dotty:

在Java中可视化图表

答案2

得分: 0

你的要求陈述得比较宽泛,但以下是一些回答:

  • 如果你希望“in search of”来放置节点和边,那么上面的答案是适用的。
  • 如果你想要自己放置节点,Graphviz支持这一点 - 在FAQ中搜索“already have all the coordinates for the nodes”即可。使用dot -Tdot yourinputfile将会给出一个输出示例,你需要创建类似的输出。在边上可以省略pos参数。
  • 如果你想同时放置节点和边,请参考上面的内容,但在边上包括pos参数,并使用neato -n2命令(边总是弯曲的,但是直线边的计算很容易)。
  • Java中没有可用于图形的程序吗?
  • 如果你想定位节点和边,但不喜欢Graphviz的解决方案,可以尝试使用dpic(https://ece.uwaterloo.ca/~aplevich/dpic/)。它的抽象层次稍低,能够提供更多的控制。

祝你好运

英文:

Your requirements are loosely stated, but here are some answers:

  • If you want 'in search of' to place both nodes & edges, then the answer above works
  • If you want to place the nodes yourself, graphviz supports this - search the FAQ for "already have all the coordinates for the nodes". dot -Tdot yourinputfile will give an example of the output you need to create. You can skip the pos on the edges.
  • If you want to place both nodes and edges, see above but include the pos on the edges and use neato -n2 (edges are always splines, but straight edges are easy to calculate)
  • Doesn't java have graphice routines you could use?
  • If you want to position nodes and edges but don't like the graphviz solution, try dpic (https://ece.uwaterloo.ca/~aplevich/dpic/) It is slightly lower-level and gives you more control

Good luck

huangapple
  • 本文由 发表于 2020年4月8日 06:23:37
  • 转载请务必保留本文链接:https://go.coder-hub.com/61090338.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定