Currently, I create chart in client browser, using highcharts; Export them as svg with highcharts inbuilt export option; I use canvg to generate png base64 image string from exported svg; Then, I send generated base64 string to server. They work great. But I am looking for a program, that can run Javascript in linux server itself, so that I can create chart and generate png base64 image string in the server itself and store them for other use.
I read about PhantomJs, ZombieJs. But they both look like a headless browser program (a browser program that doesn't have User Interface) which is used only for testing purpose. I don't know if I have an option in these packages(PhantomJs,ZombieJs) to run my javascript program and return me image string.
Can anyone suggest me an answer that best suits me?
Thanks! Jeffrin
It sounds like you've already got a solution working using Javascript in a web browser. You just want to do the SAME thing from NodeJS, correct?
It also sounds like displaying the result in a web browser is a perfectly acceptable solution for you (as opposed to using X Windows, or something like that). Correct?
Easy peasy :)
To run under NodeJS, just do EXACTLY THE SAME THING.
Take the JS code you're running locally in your browser ... and copy/paste it into a NodeJS request handler.
The client connects to your server by browsing to the NodeJS web app.
NodeJS returns the SVG as the "response" object sent by the request handler back to the browser. And voila! The client sees the chart or graph displayed in the browser.
Q: Sound reasonable?
Here are a couple of links that might help:
Your First NodeJS HTTP Server
How to serve an image using nodejs
ADDENDUM:
Use npm to install highcharts-more-node
There are many ways to invoke your charting code with NodeJS, including:
a)
require('http'): run your charting code from an HTTP request handlerb) Run
nodedirectly from the command lineEither of these options allow you many ways to save your file - WITHOUT needing any "extra steps" (like you're apparantly doing now):
See also: 4 different ways to save a Highcharts chart as a PNG (with and without a server)