Highcharts SVG Export from Python Server Side Code
-
04-10-2019 - |
سؤال
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.
المحلول
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.
نصائح أخرى
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.