PhantomJS-Google-Charts
PhantomJS-Google-Charts copied to clipboard
use within Node server
How would I integrate this into my node app? I'm using Node.js/Hapi.js to render Views server-side. I want to add charts to those reports and render them server-side. Your solution looks great!
I'd appreciate it if you could point me toward how to add it to node.
Thanks! Donnie
It looks like there is a PhantomJS node package https://www.npmjs.com/package/phantomjs . Would that work with this project? How do you install PhantomJS-Google-Charts?
To install, you just copy down the js file in the repo and include the js file into your app. You have to use PhantomJS to use this script. You cannot use NodeJS alone because the Google Charts API requires a DOM and Node does not provide one (to my knowledge).
I am not a javascript developer and I do not use NodeJS or PhantomJS on a regular basis, so I am not sure if that package you found will work or not.
Thank you @pstephan1187 . I've ask the makers of the phantomJS node package how to call your function from Node. We'll see if they respond.
@pstephan1187 , what is the file format I should use if I want to store your example phantomJS script? The node package appears to allow me to load a file into PhantomJS and run it. I tried saving your example as a js, but that wouldn't load.
Thanks
Forget my last question and that package won't work because it just installs phantom. this one might https://www.npmjs.com/package/phantomjs-wrapper
I know you are not a javascript developer, but does the code on this page look familar to you on the phantom side? I would think I would create a page can include your script in it. But I don't know how to put the two together ... yet.
Thoughts?
I appreciate any help.
Donnie
I know to get it to work with PhantomJS I just had the main js file that I executed from the command line. That file required the phantom file and the charts file. It looks like the Wrapper script would literally just wrap the phantom code in a phantomjsWrapper method. Maybe something like this:
phantomjsWrapper = require('phantomjs-wrapper');
phantomjsWrapper({timeout: 60000}, function(err, phantomjs) {
var GC = require('./googleCharts.js');
var jsonData = {
"type": "PieChart",
"options": {
"title": "Type of Fruit Eaten",
"width": "400",
"height": "300",
"is3D": true,
"pieSliceText": "value"
},
"columns": {
"Type": "string",
"Eaten": "number"
},
"rows": {
"Bananas": 4,
"Apples": 2,
"Oranges": 6,
"Mangoes": 3
}
};
GC.generateChart(jsonData, function(svgHtml){
console.log(svgHtml);
phantom.exit();
});
});
I am only guessing. I just glanced at the documentation and have not tested the above code, but that should get you started.
Thank you! I'll give this a try. Glad to know it might not need a "page" created. I just want the svgHtml so I can return it in my node route.
Seems to run in this way. But I get this error.
Error: Cannot find module 'webpage' at Function.Module._resolveFilename (module.js:336:15) at Function.Module._load (module.js:278:25) at Module.require (module.js:365:17) at require (module.js:384:17) at Object.exports.generateChart (C:\Program Files\iisnode\www\googleCharts.js:36:13)
The google charts script requires webpages to work. You may need to include that somehow.
On Sep 27, 2015, at 8:55 AM, Don Kerr [email protected] wrote:
Seems to run in this way. But I get this error.
Error: Cannot find module 'webpage' at Function.Module._resolveFilename (module.js:336:15) at Function.Module._load (module.js:278:25) at Module.require (module.js:365:17) at require (module.js:384:17) at Object.exports.generateChart (C:\Program Files\iisnode\www\googleCharts.js:36:13)
— Reply to this email directly or view it on GitHub.
I've opened and issue with https://www.npmjs.com/package/phantomjs-wrapper because, as I understand it, it is supposed to load phantomjs, which I assume that means all modules it requires.