混合服务器端java和客户端JavaScript图表库?

问题描述:

有没有库来为同一数据生成相同的图表,无论是在Java还是Javascript?

Is there a library to generate same charts for the same data, both in Java and Javascript?

我的任务是:


  • 在浏览器中显示一些闪烁的动态图表在动态工具提示,缩放等方面更好(我在这里思考Javascript)

  • 并在服务器端生成相同(或类似的)图表,在Java中,自动发送在电子邮件(在这种情况下根本没有浏览器)。 li>
  • display some flashy dynamic chart in a browser, better with dynamic tooltips, zooming and so on (I'm thinking Javascript here)
  • and generate the same (or similar enough) charts on server side, in Java, for automatically sending them in emails (no browser at all in this scenario).

我想避免Flash的iPhone互操作性。

I'd like to avoid Flash for iPhone interoperability.

静态服务器端图表如Eastwood / JFreeChart,但我想让它在浏览器中更活。

There are some static server-side charts like Eastwood/JFreeChart, but I'd like to make it more alive in browser.

是的,我可以通过Ajax重新加载静态图像。还有其他选择吗?

Yes I can reload static images via Ajax. Are there other options?

这个问题是多少年,但没有答案?我建议一个相当有问题和有点硬核的方法。

以下是您的成功公式: d3.js + jsdom + Rhino + 蜡染

Here's your success formula: d3.js+jsdom+Rhino+Batik

具体来说:


  1. 使用像 d3.js 这样的一些漂亮的JavaScript库。

  1. Generate your graphs using some slick JavaScript library like d3.js.

使用 jsdom 运行d3服务器端。

Use jsdom to run d3 server-side. Jsdom is pure JS library and d3 is known to be working on top of it.

Rhino - 一个JavaScript引擎,从1.6开始融入你喜爱的JVM中()。虽然,我建议您将其更新到最新版本(它在Maven Central,整洁!)。我猜 Node.JS 可以做得更好,但我认为你坚持使用Java。

Run jsdom and d3 inside Rhino - a JavaScript engine baked into your beloved JVM since 1.6 (yay, JSR-223!). Although, I suggest you updating it to latest release (It's on Maven Central, neat!). I guess Node.JS can do a better job but I assume that you're stuck with Java.

另请注意,有一个较老的,更成熟的和Rhino特定的服务器端DOM实现 - EnvJs 需要Rhino 1.7R2,而不是R3 。你可以试试,如果jsdom不适合你。

Also note that there's an older, more mature and Rhino-specific server-side DOM implementation - EnvJs (requires Rhino 1.7R2, not R3). You can try it if jsdom doesn't work for you.

使用蜡染光栅化由d3生成的SVG 。 Batik甚至支持通过Rhino在SVG中执行脚本。这意味着您可以生成交互式图表服务器端if你想要。

Use Batik to rasterize an SVG generated by d3. Batik even supports scripting inside SVG via Rhino. That means you can generate interactive charts server-side if you want to. I also used it in practice and had great experience with it.

整个方法已知可以工作在服务器端使用Node.JS作为JS引擎, ImageMagick作为一个光栅化器,但我没有看到为什么它不会为你工作的理由。

The whole approach is known to work server-side with Node.JS as a JS engine and ImageMagick as a rasterizer but I see no reasons why it wouldn't work for you as well.

BTW,如果你让它所有运行让我知道。

BTW, If you'll make it all running let me know.