This project is an adaptation of the original node-googlecharts by zallek, all credits go to zallek.
The original project uses the old GoogleCharts API so I decided to update it, right now it uses the latest GoogleCharts API and also the last JSDOM version, also I added some new features.
node-googlecharts allows you to have a server-side graph generation tool that can than deliver the result to the client via something like an API.
- Node.js > 4.0
- ICU4
- node-canvas
Google Chart needs full internationalization support whereas it's not built in by default on nodejs. You can either:
- Use full-icu npm package which requires running node with a specific environment variable.
- Or, build Node.js with an embedded icu. more info
node-googlecharts allows you to extrat a chart image both in SVG or PNG(Base64) format. To do so you simply have to call the render()
function with the <ChartWrapperOptions>
, <ExtractFormat>
and <ForceUncutLine>
as parameters.
Argument | Type | Description |
---|---|---|
ChartWrapperOptions |
JSON | Uses default GoogleCharts Options |
ExtractFormat |
String | Can either be svg or png |
ForceUncutLine |
Boolean | Forces legends to be single line without being cut off |
$ node bin/node-googlecharts '<ChartWrapperOptions>'
or
$ npm run bin '<ChartWrapperOptions>'
ChartWrapperOptions
is the serialized JSON options to give to ChartWrapper
.
{
"chartType": "ColumnChart",
"dataTable": [
["", "Germany", "USA", "Brazil", "Canada", "France", "RU"],
["", 700, 300, 400, 500, 600, 800]
],
"options": {
"title": "Countries"
}
}
If you wish to use this project as a node_module to use in your API or other projects, simple type the following command in your command line:
$ npm install 3nvy/node-googlecharts --save
Then you just need to require the project name and its done.
Google Charts needs a browser-like environment to run in. Jsdom is a light DOM implementation, much faster than PhantomJS.
This is a requirement of jsdom itself.
We need a virtual canvas to be able to calculate the currect size of the chart legends, allowing for text wrapping
Google Chart needs full internationalization support whereas it's not built in by default on nodejs.