从 Python 服务器端代码导出 Highcharts SVG
我正在 python 中使用 reportlab 来渲染 pdf 服务器端。
我真的很喜欢 highcharts 图表的外观。但我正在构建一个 pdf 服务器端,它需要包含一些图表。服务器端绘图(reportlab 和 matplotlib)没有那么多的格式化/设计选择。
有没有办法可以从服务器端运行客户端 JavaScript 图形解决方案(highcharts)?
这是一个带有该请求的帖子,这就是他们所说的: 您向该 Java 工具提供一个 URL,它会启动其内部 WebKit 浏览器,执行 JavaScript 代码并将渲染的页面转储为 PDF。
我正在寻找有关如何在 python 中实现这一点的资源。
I am using reportlab in python to render a pdf server side.
I really like the look of highcharts graphs. But I am building a pdf server side which needs to include some graphs. The server side graphing (reportlab and matplotlib) do not have nearly as much choices for formatting / design.
Is there a way I can run a client side javascript graphing solution (highcharts) from the server side?
Here is a post with that request and this is what they said:
You feed this Java tool a URL, it fires up its internal WebKit browser, executes the JavaScript code and dumps the rendered page to PDF.
I am looking for resources on how this could be accomplished in python.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
我有类似的要求,但找不到现有的解决方案,因此我创建了一个小的概念验证解决方案 这里。
此实现的工作原理是让 python 进程创建一个使用
highchart-export-server
节点模块的节点子进程,该模块又生成一个 PhantomJS 实例来渲染图表。那里涉及一些俄罗斯娃娃,但它确实起到了作用。I had similar requirements and couldn't find an existing solution so I created a little proof-of-concept solution here.
This implementation works by having the python process create a node subprocess that uses the
highchart-export-server
node module which in turn spawns a PhantomJS instance to render the chart. A few russian dolls involved there, but it does the job.在服务器上打开 Web 浏览器。
将网络浏览器指向加载
highcharts
并呈现图表的预制页面。获取浏览器的输出。
将其发送给客户端。
其中哪一个步骤看起来令人困惑?
请注意,这比仅使用 matplotlib 慢得多,因为您需要启动完整的 Web 浏览器才能渲染图形。我快速浏览了您链接的 highcharts 页面,我认为您可能可以在 matplotlib 中重现该页面。
Open a web browser on the server.
Point the web browser at a pre-made page that loads
highcharts
and renders your chart.Grab the output of the browser.
Send that to a client.
Which of those steps seems confusing?
Note that this will be significantly slower than just using
matplotlib
, because you need to start up a full web browser just to render a graph. I had a quick look at the highcharts page you linked and I think you could probably reproduce that in matplotlib.