8

I have a node.js application that accesses data of a MySQL database and I want to generate charts from that data dynamically, to pipe it as image (PNG/JPG) through a HTTP server to the user. I've search for a little while now, but I was unable to find a library to do this without the HTML/canvas approach. Since I want to let the server do the rendering to use the graph in emails or also dynamically rendered PDF files, this isn't an option here.

What could be the approach here (with or without a library) ?

Edit to provide proof of own work: I found https://plot.ly, which is in terms of usage and result really close to fulfil my needs, but requires an internet connection, since it calls a remote API.

XQDev
  • 366
  • 4
  • 15
  • Clearly off topic (read [ask]). why would anyone upvote this? – Amit Jan 18 '16 at 12:10
  • I edited the question to make it more obvious to passing by users that this is a real question and not a request for a library. – Denys Séguret Jan 18 '16 at 12:10
  • Why canvas isn't an option? You can render on canvas and get the image data to either send to the client or save on the server for later use in pdfs or whatever. – pawel Jan 18 '16 at 12:12
  • @DenysSéguret - what's the difference? The functionality obviously isn't there, and the question is not "I've implemented a JPG module but I have this little pesky bug I need help with". This is off topic. – Amit Jan 18 '16 at 12:12
  • @Amit The question, IMO, is about what's a feasible strategy to generate a chart image server side given there doesn't seem to be any library to do this with node (*disclaimer: I didn't check that claim*). – Denys Séguret Jan 18 '16 at 12:14
  • You could draw the chart using SVG and then convert to JPG. – Jason Kennaly Jan 18 '16 at 12:15
  • 1
    You could use python for chart rendering. take a look at this thread: http://stackoverflow.com/questions/10775351/combining-node-js-and-python – Hauke S Jan 18 '16 at 12:17
  • @DenysSéguret - do you see any feasible answer that doesn't involve either "use library X" or "create library Y, that you can base on existing library Z in language/domain Foo"? (Like Hauke just did) – Amit Jan 18 '16 at 12:17
  • Dear Amit: I apologize in case my question isn't clear enough. Since I'm handling the above described problem for only a few hours, I'm not aware of the amount of possible solutions. (Or the absence of other solutions, beside any libraries) Since I don't believe that I'm the first that comes up with that need, I though there could be some clever or elegant way to render the HTML/canvas on server to image. (And I'm not stuck to library solutions, since I'm not aware of other possibilities. Other approaches, if possible, are welcome) – XQDev Jan 18 '16 at 12:21
  • 1
    You could try a chartist wrapper for node: https://github.com/panosoft/node-chartist – hansmaad Jan 18 '16 at 12:23
  • XQDev - looks like you got a few library suggestions (exactly like I expected to happen). Other then that what you're asking for is someone to create a library for you here on SO. I don't see that happening. Good luck anyway. – Amit Jan 18 '16 at 12:38
  • Dear Amit, I don't need anyone to create a library for my task. I asked for existing solutions or a good way to create my own solution, even if the solution could mean to execute console based tools like rrdgraph (on Linux). A library would be great, of course, since I can stick to work on the task and not on the tools. – XQDev Jan 18 '16 at 13:55

3 Answers3

9

You could also try asking this in the Software Recs Stack Overflow. But one option that seems like it could fit your needs is ZingChart.

They have a phantomJS build for rendering static versions of charts. In addition, licensed users can access a Node.js build for server side charting.

Full disclosure, I'm on the ZingChart team so please let me know if I can help you review all your options.

Merrily
  • 1,686
  • 10
  • 14
2

There is a node wrapper for the chart library chartist. You could use this library to generate a SVG, and a svg2png lib to convert to PNG.

hansmaad
  • 18,417
  • 9
  • 53
  • 94
2

Well there are multiple options, I would use phantomjs (headless Webkit browser) to render the charts.

Why would this option be good? One of the reasons is that you don't need duplicated code for the server and client side coding, you could simply reuse the code. On server side create a html file with required scripts and data and render it.

Risto Novik
  • 8,199
  • 9
  • 50
  • 66