google-charts-node
google-charts-node copied to clipboard
GeoChart Error: Must draw chart before calling getImageURI
Reproduce
(async () => {
const drawChart = `
var container = document.getElementById('chart_div');const data = google.visualization.arrayToDataTable([['Country', 'Popularity'],['Germany', 200],['United States', 300],['Brazil', 400],['Canada', 500],['France', 600],['RU', 700]
]);var options={};var chart = new google.visualization.GeoChart(container);chart.draw(data, options);
`;
const image = await GoogleChartsNode.render(drawChart, {
width: 400,
height: 300,
package: 'geochart'
});
fs.writeFileSync('/tmp/google-chart.png', image);
})();
@typpo Any thoughts on this? I'm experiencing the same issue
Python example, inspired by: https://developers.google.com/chart/interactive/docs/gallery/geochart
import requests
code = '''
var container = document.getElementById('geochart');
var chart = new google.visualization.GeoChart(container);
var data = google.visualization.arrayToDataTable([
['Country', 'Popularity'],
['Germany', 200],
['United States', 300],
['Brazil', 400],
['Canada', 500],
['France', 600],
['RU', 700]
]);
var options = {}
chart.draw(data, options);
'''
resp = requests.post('https://quickchart.io/google-charts/render', json={
'width': 600,
'height': 300,
'packages': 'geochart', # optional
'code': code,
'mapsApiKey': '<MY GMAPS API KEY; however, it gives the same error regardless>',
})
with open('chart.png', 'wb') as f:
f.write(resp.content)
Execution
$ python quickchart.py
$ cat chart.png
Error: Evaluation failed: Error: Must draw chart before calling getImageURI.
at gvjs_E_.gvjs_.ah (https://www.gstatic.com/charts/51/js/jsapi_compiled_geochart_module.js:81:133)
at __puppeteer_evaluation_script__:5:25%