I would like to use a Javascript library (Flot) to generate charts in my application. Most of the time, the charting will be performed by clients. However, I can see that in some cases, where the same charts would be frequently accessed by all clients, it would be better to generate those charts on the server, cache them, and serve them as images.
How could I go about executing Javascript from a script that runs on the server? Can Flot be used to generate PNG's?
This should be possible with Node.js and node-canvas. Node-Canvas can spit out PNGs for your cached graphs.
Related
I am working on an application which is loading XML files and displaying data in SVG charts (line chart). This application needs to be fast.
The problem is that the implementation of this app has already started and it is completely based on JavaScript. I was told that this app needs to load and parse multiple very big XML files (up to 80 MB) and it needs to be very stable. So as JS is not able to parse such big XML files, they are loaded line by line and parsed as strings. When data is parsed, it is displayed in SVG charts which is another problem. There can be a lot of charts with a lot of data so sometimes browser cannot handle it.
My idea was to do it on the server-side, using SAX parsers and lazy loading on charts, but I cannot because people who are going to use it, they want to use it offline.
So now I would like to know if such thing can be done with JS only or do I have to use server or desktop app .
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
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/
I want to generate some reports in a MEAN.js Application, that said, i manage the data in Angular, what i want to know is if there's a library to generate a PDF Report, for example, when using PHP there's dompdf, fpdf, etc...
Basically what i need to generate is something like this from Angular:
Are there any tool to generate the reports from Angular, or should i generate them from Node.js? if so what are the tools available for node.js?
I only know about jsreport for node.js
Server-side rendering with Node is definitely the way to go, the client side libraries never really worked well (I last checked about a year ago). I'd suggest using PhantomJS as it provides PDF rendering capabilities out of the box.
PhantomJS will use Webkit engine to generate the PDF for you. The actual rendering process is dead simple:
page.render('/tmp/file.pdf', function() {
// file is now written to disk
});
Of course you have to insert something on the page you're generating first. Check out the following post which describes one guy's implementation, the code quoted above comes from there: http://www.feedhenry.com/server-side-pdf-generation-node-js/
I have some scripts written with d3.js that generate SVG charts. I'd like to generate those charts with a standalone program -- what is the easiest way I can convert those scripts to run in batch mode, without a browser?
You could:
Convert this to a node.js program. You'd have access to the filesystem and would be able to save generated SVGs easily. You'd need node-canvas to replace the HTML canvas. See this d3 example to get started using d3 with node.
You could use the filesystem APIs in Chrome with your existing scripts to write files to the hard disk. This may be easier, because you would just need to implement the filesystem code on top of what you have already. See this html5rocks article for information on writing to the local file system.
I'm looking to use this chart generation library: http://www.jqchart.com/
Ideally, I would prefer to use a PHP charting library for the current project I'm working, but, by the looks of it, this is the only library I've found that can handle what I need to do (given a somewhat unconventional requirement for the charts).
The issue is that I need to get the generated graphs as images (at the moment each graph seems to be a combination of images) to the server so that I can generate some PDF documents, etc.
I'm thinking of attempting to create an image using JS, pushing this back to the server and then generating the PDF although this pretty nasty and will probably cause issues between different versions of the browser.
So now what I'm looking for is a solution that will allow me to generate the graphs and turn them into images on the backend.
Any ideas?
EDIT: For the requirement that led me to rule out a number of other charting libraries, see here: Complex charts in Google Charts
That really isn't all that relevant to the question of processing Javascript on the server, though.
You can render a javascript graph on the server using phantomjs. Here is an example.
Not sure what your requirements are, but I'd check out Google Chart Tools: http://code.google.com/apis/chart/. It's really simple to use. All the data is in the image URL get request, so you can generate charts using client-side JavaScript too.