优化网络图表绘制
我想将有向图渲染到浏览器中显示的 servlet/图片。 应该对位置进行某种优化。 最好不依赖 Swing。 算法并不重要,因为图的结构是由业务逻辑决定的。 希望能够向边缘添加标签。 如果我可以将其作为 png/svg 提供,那将是最佳的。
您会推荐哪个图书馆/服务?
澄清:
1)问题都是关于图的 - 就像 有向非循环图 - 不是 - 图表。
2)flot,Google Charts - 无法绘制图表,只能绘制图表,或者我错过了什么?
3) 不,我不需要交互性
4) graphviz 会很好,但是 grappa java 库相当过时,并且是基于 swing/awt 构建的。 虽然理论上可以将摆动渲染为图像,但这不是我最喜欢的在服务器应用程序中实现的方式。
5) 最好使用图像不在本地托管的在线服务。
编辑:添加了维基百科的链接以澄清图形/图表术语
Having seen some suggestions for graphs, I wonder what's the optimum for my problem.
I want to render a directed graph to a servlet/picture that is displayed in the browser. There should be some kind of optimization of position. No dependency to Swing would be preferred. Algorithms are not important, since the structure of the graph is determined by business logic. It would be desired to be able add labels to edges as well.
it would be optimal if i can serve this as png/svg.
Which library/service would you recommend?
clarifications:
1) The question is all about Graphs - like Directed Acyclic Graph - NOT - Charts.
2) flot, Google Charts - cannot plot graphs, only charts, or have i missed something?
3) no i do not need interactivity
4) graphviz would be nice, but the grappa java library is quite outdated and is built upon swing/awt. while it may be theoretically possible to render swing to images, it would not be my favorite way to to so in a server-app.
5) it would be fine to use an online service where the images are not hosted locally.
edit: added links to Wikipedia to clarify graph/chart term
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(16)
有趣的是,Eclipse 项目有一个 SWT/JFace 组件/框架,能够以纯 Java 形式显示和生成(导入/导出)Graphviz 的“DOT”格式:
ZEST(主页和下载链接)
请参阅 http://wiki.eclipse .org/Graphviz_DOT_as_a_DSL_for_Zest 了解使用示例。
尽管 ZEST 被宣传为 Eclipse 插件,但 DOT 操作 API 似乎可以独立使用并在 Eclipse 安装外部使用。
干杯
丰富
Interestingly, the Eclipse project has an SWT/JFace component/framework capable of displaying and generating (import/export) Graphviz's 'DOT' format, in pure Java:
ZEST (home page & download links)
See http://wiki.eclipse.org/Graphviz_DOT_as_a_DSL_for_Zest for usage examples.
Although ZEST is touted as an Eclipse plugin, it does seem that the DOT-manipulation API's can be used standalone and external to an Eclipse installation.
Cheers
Rich
您可以尝试 sigma.js: http://sigmajs.org/
它是一个轻量级的 Javascript 开源库在 Web 上显示大图。
You may try sigma.js: http://sigmajs.org/
It is a lightweight, open source library in Javascript to display large graphs on the Web.
JPGD 是 Java 中的 Graphviz 解析器。 它有点被遗弃,但是代码很好而且清晰,如果您发现错误,我相信作者会接受贡献的修复。
虽然宣传为解析器,但它也是一个生成器。 您可以将图构建为 Node 和 Edge 对象的集合,然后使用 Graph.toString() 获取 .dot。 将其作为图形获取是 Graphviz dot 可执行文件的简单外壳。
或者,dot 很容易自己生成。 在最简单的情况下,只需编写一个盆栽标头
...然后是每个边缘的一个边缘定义
...然后是一个右大括号
JPGD is a Graphviz parser in Java. It's a little abandoned, but the code is nice and clear, and if you find bugs I'm sure the author would accept contributed fixes.
Although advertised as a parser, it is also a generator. You can build Graphs as collections of Node and Edge objects, then get .dot using Graph.toString(). Getting this as a graphic would be a simple shell out to the Graphviz dot executable.
Alternatively, dot is very easy to generate yourself. In the simplest case, it's just a matter of writing a potted header
... followed by one edge definition per edge
... followed by a closing brace
所以我查看了所有给定的答案和链接,它看起来像 Prefuse/Flare 将是最佳选择。
它们具有非常吸引人的可视化效果,而且还内置了对图表的支持。
so i took alook at all the given answers and links, it looks like Prefuse/Flare will by the optimal choice.
they have very appealing visialisations, plus they have built in support for graphs.
也许可以查看 Google 图表?
Maybe check out Google Charts?
您可以将 SVG 与 Batik 结合使用。 我已经多次使用它来显示图形。 使用 Java 1.5 的蜡染速度非常快。 使用此解决方案,您可以使用 Java 对图形进行编程,而不依赖于 Swing。 您可以在所需位置添加标签,将其托管为 Servlet 并将其显示为 png 或 svg。
您可以在 SVG 中创建图形(这是一个 XML 文档)。
您可以使用 Batik 将 SVG 文档转换为 PNG/JPG 图像。
您可以使用 Servlet 将此图像流式传输回浏览器。
在 Java 中,您可以构建一个 SVG(=XML) 文档。 SVG 图表的示例可以在这里找到:
有向图 和此处:简单有向图
You can use SVG in combination with Batik. I have used this several times for displaying graphics. Batik with Java 1.5 is very fast. With this solution you can program your graph in Java with no dependency on Swing. You can add labels where you want, host it as a Servlet and display it as png or svg.
You can create the graphs in SVG (this is an XML document).
You use Batik to transform the SVG-document to a PNG/JPG image.
You can use a Servlet to stream this image back to the browser.
In java you build an SVG(=XML) document. Samples for SVG graphs can be found here:
Directed graph and here: Simple directed graph
请参阅这个问题,特别是Stephan关于prefuse的回答。 我读到您不需要交互性,但 prefuse 仍然可能有用。
See this question, especially Stephan's answer about prefuse. I read that you do not need interactivity, but prefuse still may be useful.
我可以全心全意地推荐 flot - 非常棒!
请参阅此处的示例。
I can whole-heartedly recommend flot - excellent!
See examples here.
JFreeChart 可能是您想要的方式,但您要区分图表和图形。 也许你可以解释一下你的意思。 我通常将这些术语作为同义词使用。 :)
JFreeChart 有很好的散点图、条形图和折线图,以及 Pie 和 Dial 等有趣的图,所以也许它会适合您。
JFreeChart might be the way you want to go, but you make a distinction between Charts and Graphs. Maybe you can explain what you mean by that. I've usually used these terms synonymously. :)
JFreeChart has good scatter, bar and line graphs as well as fun ones like Pie and Dial so maybe it will work for you.
看看 graphviz
Take a look at graphviz
yFiles 可能对此有用。
yFiles might be useful for this.
Graphviz 的点组件怎么样? 它生成图形(不是图表),输出为 PNG 和 SVG,并支持标记边缘。 您可以使用 dot 来生成所需的图像,并返回引用该图像的 img 标签。 或者,您可以返回一个引用 URL 的 img 标签,该 URL 将生成必需的图表(或检索缓存的副本)。 这是点信息:
http://www.graphviz.org/pdf/dotguide.pdf
您还可以看看 WebDot,它显然是为此目的而设计的:
http://www.graphviz。组织/webdot/
How about the dot component of Graphviz? It produces graphs (not charts), outputs to PNG and SVG, and supports labeling edges. You can shell out to dot to generate the image you need, and return an img tag that references that. Alternatively, you can return an img tag that references a URL that will generate the requisite graph (or retrieve a cached copy). Here's the dot info:
http://www.graphviz.org/pdf/dotguide.pdf
You might also take a look at WebDot, which is apparently designed for this purpose:
http://www.graphviz.org/webdot/
除了等待几周才能听到神奇框架将在一行代码中解决您的所有问题之外,还有另一种选择,您自己编写一些代码来完全完成您想要的事情......(我不是说这是 10 分钟的工作,但可能需要一两天,而且您在两周前发布了您的问题...)
例如,您是否看过 基于力的算法——它有伪代码和一些可能有用的链接。
我假设问题在于布局算法,而不是创建 BufferedImage、绘制到其图形上下文、对其进行 PNG 编码并将其发送到套接字的问题。 我认为你真的不需要一个框架来实现这一点。
As well as waiting weeks to hear about the Magic Framework that's going to solve all your problems in one line of code, there is also the other option of just Writing Some Code yourself to do exactly what you want... (I'm not saying it's 10 minutes' work, but it's probably one or two days, and you posted your question over two weeks ago...)
Have you had a look, for example, at the Wikipedia entry on Force-based algorithms-- it has pseudocode and a few links that might be helpful.
I'm assuming it is the layout algorithm that's the issue, and not the matter of creating a BufferedImage, drawing to its graphics context, PNG-encoding it and sending it down the socket. You really don't need a framework for that bit, I don't think.
尝试aiSee。 它被各种基于网络的应用程序用于数据挖掘,静态程序分析,矩阵可视化, 网络分析,等等。 它也被一些 MediaWikis 作为他们的图表 -布局后端。
他们在 aiSee.com 上拥有一个庞大的样本图表数据库。 一探究竟。 它支持边缘标签、导出到映射的 SVG 和 HTML,并且不依赖于 Swing。
Try aiSee. It is used by all kinds of web-based applications for data mining, static program analysis, matrix visualization, network analysis, and whatnot. It is also used by some MediaWikis as their graph-layout backend.
They have a huge database of sample graphs over at aiSee.com. Check it out. It supports edge labels, export to mapped SVG and HTML, and is not dependent on Swing.
我们为此类需求创建了 mxGraph。 我们确实在 2006 年发布了它,但花了一段时间才注意到这个问题......
We create mxGraph for such requirements. We did actually release it in 2006, but took a while to notice this question...
对于服务器端,请尝试JUNG,您可以针对Batik 并生成漂亮的 SVG 或 PNG 文件。 JUNG 有一个很好的设计和非常强大的布局算法...
另外,既然你提到“使用在线服务就可以了”,graphviz 提供了一个名为webdot 来渲染图表。
还有其他一些沿着这条线......例如 http://graph.gafol.net/ (似乎已关闭)
客户端:
尝试http://arborjs.org/ 对于一个最小的(ish)库,它专用于布局,如果您喜欢自己的渲染例程(div、canvas、svg、paper.js、处理...等),请使用它。
我也喜欢 http://sigmajs.org/ 以获得更完整的方法,建立联系支持,插件、文件格式等。
For serverside, try JUNG, you can run it against Batik and produce beautiful SVG or PNG files. JUNG has a nice design and very powerful layout algorithms...
Also, since you mention that "it would be fine to use an online service", graphviz provide a service called webdot to render graphs.
There are others along this line as well... e.g. http://graph.gafol.net/ (seems to be down)
Client side:
Try http://arborjs.org/ for a minimal(ish) library it is dedicated to layout, use this is you like to prefer your own rendering routines (div, canvas, svg, paper.js, processing... etc).
I also like http://sigmajs.org/ for a more complete approach, build in touch support, plugins, file formats, etc.