混合服务器端 java 和客户端 javascript 图表库?
是否有一个库可以用 Java 和 Javascript 为相同的数据生成相同的图表?
我的任务是:
- 在浏览器中显示一些华丽的动态图表,更好地使用动态工具提示、缩放等(我在这里考虑Javascript)
- 并在服务器上生成相同(或足够相似)的图表side,在 Java 中,用于自动在电子邮件中发送它们(在这种情况下根本不需要浏览器)。
我想避免使用 Flash 来实现 iPhone 互操作性。
有一些静态服务器端图表,例如 Eastwood/JFreeChart,但我想让它在浏览器中更加活跃。
是的,我可以通过 Ajax 重新加载静态图像。还有其他选择吗?
Is there a library to generate same charts for the same data, both in Java and Javascript?
My task is both:
- 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).
I'd like to avoid Flash for iPhone interoperability.
There are some static server-side charts like Eastwood/JFreeChart, but I'd like to make it more alive in browser.
Yes I can reload static images via Ajax. Are there other options?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
为什么这个问题已经一年多了却没有答案?!我建议采用一种相当有问题且有些硬核的方法。
使用 JavaScript,这太棒了!
这是您的成功公式:
d3.js
+
jsdom
+
Rhino
+
Batik
具体来说:
使用一些灵活的 JavaScript 库(例如d3.js<)生成图表< /a>.
使用 jsdom 运行 d3 服务器端。 Jsdom 是纯 JS 库,众所周知 d3 正在其之上工作。
在 Rhino 中运行 jsdom 和 d3 - 自 1.6 起就内置于您喜爱的 JVM 中的 JavaScript 引擎(< a href="http://jcp.org/aboutJava/communityprocess/pr/jsr223/index.html" rel="noreferrer">耶,JSR-223!)。不过,我建议您将其更新到最新版本(它位于 Maven Central 上,简洁!)。我猜 Node.JS 可以做得更好,但我假设您仍然使用 Java。
另请注意,有一个更旧、更成熟且特定于 Rhino 的服务器端 DOM 实现 - EnvJs < em>(需要 Rhino 1.7R2,而不是R3)。如果 jsdom 不适合你,你可以尝试一下。
使用Batik 光栅化 d3 生成的 SVG。 Batik 甚至支持通过 Rhino 在 SVG 内编写脚本。 这意味着您可以生成交互式内容如果需要的话,可以在服务器端绘制图表。我也在实践中使用过它,并获得了很好的经验。
整个方法已知有效< /strong> 服务器端,使用 Node.JS 作为 JS 引擎,使用 ImageMagick 作为光栅化器,但我认为它没有理由不适合你。
顺便说一句,如果你能让一切正常运行,请告诉我。
How come this question is more than a year old but got no answers?! I suggest a rather questionable and somewhat hardcore approach.
Use JavaScript, it's awesome!
Here's your success formula:
d3.js
+
jsdom
+
Rhino
+
Batik
Specifically:
Generate your graphs using some slick JavaScript library like d3.js.
Use jsdom to run d3 server-side. Jsdom is pure JS library and d3 is known to be working on top of it.
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.
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.
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.
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, If you'll make it all running let me know.
请原谅这么晚的回复,但是使用 Highcharts 怎么样?我正在寻找在输入此内容时为您提供更多信息的链接,但 Highcharts 提供了服务器端“导出”功能。它的基本作用是允许您下载图像的副本,而实际上不需要浏览器。
我实现了此功能,以便我可以获取请求参数、查询数据存储、使用 Highcharts 将这些数字绘制到所需的图表中并将这些结果嵌入到电子邮件中(当然,还将电子邮件发送给收件人)。
更多信息请参见:http://www .highcharts.com/component/content/article/2-articles/news/52-serverside- generated-charts
和
此处:https://github.com/one2team/highcharts-serverside-export
Pardon the really late reply, but how about using Highcharts? I'm looking for the link which provides you more information as I'm typing this, but Highcharts provides a server-side 'export' feature. What it basically does is it allows you to download a copy of an image without actually requiring a browser.
I implemented this feature so that I could take take request parameters, query a data-store, plot those numbers using Highcharts to a desired graph and embed those results in an email (and of course, send the email out to the recipients).
More information here: http://www.highcharts.com/component/content/article/2-articles/news/52-serverside-generated-charts
AND
here: https://github.com/one2team/highcharts-serverside-export