Skip to content

Commit a8f40d3

Browse files
committed
Initial commit
0 parents  commit a8f40d3

File tree

12 files changed

+1334
-0
lines changed

12 files changed

+1334
-0
lines changed

.gcloudignore

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
# This file specifies files that are *not* uploaded to Google Cloud Platform
2+
# using gcloud. It follows the same syntax as .gitignore, with the addition of
3+
# "#!include" directives (which insert the entries of the given .gitignore-style
4+
# file at that point).
5+
#
6+
# For more information, run:
7+
# $ gcloud topic gcloudignore
8+
#
9+
.gcloudignore
10+
# If you would like to upload your .git directory, .gitignore file or files
11+
# from your .gitignore file, remove the corresponding line
12+
# below:
13+
.git
14+
.gitignore
15+
README.md
16+
17+
node_modules
18+
examples

.gitignore

Lines changed: 131 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,131 @@
1+
venv
2+
scripts
3+
4+
### Vim ###
5+
[._]*.s[a-w][a-z]
6+
[._]s[a-w][a-z]
7+
*.un~
8+
Session.vim
9+
.netrwhist
10+
*~
11+
12+
13+
### OSX ###
14+
.DS_Store
15+
.AppleDouble
16+
.LSOverride
17+
18+
# Icon must end with two \r
19+
Icon
20+
21+
22+
# Thumbnails
23+
._*
24+
25+
# Files that might appear in the root of a volume
26+
.DocumentRevisions-V100
27+
.fseventsd
28+
.Spotlight-V100
29+
.TemporaryItems
30+
.Trashes
31+
.VolumeIcon.icns
32+
33+
# Directories potentially created on remote AFP share
34+
.AppleDB
35+
.AppleDesktop
36+
Network Trash Folder
37+
Temporary Items
38+
.apdisk
39+
40+
41+
### Python ###
42+
# Byte-compiled / optimized / DLL files
43+
__pycache__/
44+
*.py[cod]
45+
*$py.class
46+
47+
# C extensions
48+
*.so
49+
50+
# Distribution / packaging
51+
.Python
52+
env/
53+
build/
54+
develop-eggs/
55+
dist/
56+
downloads/
57+
eggs/
58+
.eggs/
59+
lib/
60+
lib64/
61+
parts/
62+
sdist/
63+
var/
64+
*.egg-info/
65+
.installed.cfg
66+
*.egg
67+
68+
# PyInstaller
69+
# Usually these files are written by a python script from a template
70+
# before PyInstaller builds the exe, so as to inject date/other infos into it.
71+
*.manifest
72+
*.spec
73+
74+
# Installer logs
75+
pip-log.txt
76+
pip-delete-this-directory.txt
77+
78+
# Unit test / coverage reports
79+
htmlcov/
80+
.tox/
81+
.coverage
82+
.coverage.*
83+
.cache
84+
nosetests.xml
85+
coverage.xml
86+
*,cover
87+
88+
# Translations
89+
*.mo
90+
*.pot
91+
92+
# Django stuff:
93+
*.log
94+
95+
# Sphinx documentation
96+
docs/_build/
97+
98+
# PyBuilder
99+
target/
100+
101+
102+
### Node ###
103+
# Logs
104+
logs
105+
*.log
106+
npm-debug.log*
107+
108+
# Runtime data
109+
pids
110+
*.pid
111+
*.seed
112+
113+
# Directory for instrumented libs generated by jscoverage/JSCover
114+
lib-cov
115+
116+
# Coverage directory used by tools like istanbul
117+
coverage
118+
119+
# Grunt intermediate storage (http://gruntjs.com/creating-plugins#storing-task-files)
120+
.grunt
121+
122+
# node-waf configuration
123+
.lock-wscript
124+
125+
# Compiled binary addons (http://nodejs.org/api/addons.html)
126+
build/Release
127+
128+
# Dependency directory
129+
# https://docs.npmjs.com/misc/faq#should-i-check-my-node-modules-folder-into-git
130+
node_modules
131+

README.md

Lines changed: 71 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,71 @@
1+
google-charts-node
2+
---
3+
4+
This package allows you to render Google Charts on the server as PNG images.
5+
6+
This is made possible through the use of puppeteer, a headless Chromium browser.
7+
8+
## Example
9+
10+
```js
11+
const GoogleChartsNode = require('google-charts-node');
12+
13+
// Define your chart drawing function
14+
function drawChart() {
15+
const data = google.visualization.arrayToDataTable([
16+
['City', '2010 Population',],
17+
['New York City, NY', 8175000],
18+
['Los Angeles, CA', 3792000],
19+
['Chicago, IL', 2695000],
20+
['Houston, TX', 2099000],
21+
['Philadelphia, PA', 1526000]
22+
]);
23+
24+
const options = {
25+
title: 'Population of Largest U.S. Cities',
26+
chartArea: {width: '50%'},
27+
hAxis: {
28+
title: 'Total Population',
29+
minValue: 0
30+
},
31+
vAxis: {
32+
title: 'City'
33+
}
34+
};
35+
36+
const chart = new google.visualization.BarChart(container);
37+
chart.draw(data, options);
38+
}
39+
40+
// Render the chart to image
41+
const image = await GoogleChartsNode.render(drawChart, {
42+
width: 400,
43+
height: 300,
44+
});
45+
```
46+
47+
This produces the following image:
48+
49+
![Google Charts Image](https://i.imgur.com/ABS8FSR.png)
50+
51+
The only requirements of your `drawChart` function are that you must:
52+
- Define a `chart` variable or return your chart.
53+
- Use the provided `container` variable to render your chart.
54+
55+
## Usage
56+
57+
### render(drawChartFunction, options) -> Buffer
58+
59+
The library exposes a single function, render.
60+
61+
**drawChartFunction** is a Function or Javascript string that is evaluated in order to draw the chart. You should put your regular `drawChart` Google Charts function here.
62+
63+
**options** is a dictionary containing some settings and parameters:
64+
- **width**: Width of chart canvas (default `100%`)
65+
- **height**: Height of chart canvas (default `100%`)
66+
- **packages**: Array of Google Charts packages to import (default `['corechart']`)
67+
- **mapsApiKey**: Google Maps API key (used only for geochart and map charts)
68+
69+
## More examples
70+
71+
See the `examples/` directory for more examples of different charts.

app.js

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
const express = require('express');
2+
3+
const { render } = require('./index');
4+
5+
const app = express();
6+
7+
app.get('/google-charts', render);
8+
9+
const port = process.env.PORT || 3500;
10+
app.listen(port);
11+
console.log(`Listening on port ${port}`);

examples/barchart.js

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
const fs = require('fs');
2+
3+
const GoogleChartsNode = require('../index');
4+
5+
(async () => {
6+
const image = await GoogleChartsNode.render(drawChart, {
7+
width: 400,
8+
height: 300,
9+
});
10+
11+
fs.writeFileSync('/tmp/google-chart.png', image);
12+
})();
13+
14+
function drawChart() {
15+
var data = google.visualization.arrayToDataTable([
16+
['City', '2010 Population'],
17+
['New York City, NY', 8175000],
18+
['Los Angeles, CA', 3792000],
19+
['Chicago, IL', 2695000],
20+
['Houston, TX', 2099000],
21+
['Philadelphia, PA', 1526000],
22+
]);
23+
24+
var options = {
25+
title: 'Population of Largest U.S. Cities',
26+
chartArea: { width: '50%' },
27+
hAxis: {
28+
title: 'Total Population',
29+
minValue: 0,
30+
},
31+
vAxis: {
32+
title: 'City',
33+
},
34+
};
35+
36+
var chart = new google.visualization.BarChart(document.getElementById('chart_div'));
37+
38+
chart.draw(data, options);
39+
}

0 commit comments

Comments
 (0)