Search code examples
javascripthtmlnode.jschartsflot

Using JS Charting Libraries with NodeJS


I've got a question regarding JavaScript charting libraries (Flot Charts, to be more specific).

At the moment, every library I've come across requires an HTML document in order to work (where the chart/graph would be constructed, in a canvas element, for example), but my problem is that I'm not creating a traditional web-page/application that requires an .html document, I'm creating a bot.

The reason I'm using the chart library is to generate an image that the bot can render to the user. In order to generate the graphic, do I need to create some generic html page where I can generate the graphic and then grab it and store it with JavaScript in my NodeJS project? Or perhaps there's something that I'm missing entirely.

Any and all help is really appreciated. Thanks a lot


Solution

  • Since Javascript runs on the client and node runs on the server, you're going to have a hard time getting the server to save a snapshot of your generated graphic. That's typically done on the server side of things.

    I would switch your library to Plotly (http://plot.ly) and utilize it's Static Image Export feature:

    https://plot.ly/nodejs/static-image-export/