dataTableToCsv not found

69 views
Skip to first unread message

Joep Kt

unread,
Jul 11, 2018, 8:59:05 AM7/11/18
to Google Visualization API
I'm building a python web app to work with google's earth engine API,

I display data through javascript using chart API and want to allow users to download the data as CSV. I am confused however when reading online there are multiple ways to load the chart / visualization api's and I can't seem to find out what I am doing wrong to be able to have access to the dataTableToCsv() function.

I found this code somewhere online and checked the docs to see that this is actually a valid function:
$('#download-csv').click(function () {
var csvFormattedDataTable = google.visualization.dataTableToCsv(this.chartData);
var encodedUri = 'data:application/csv;charset=utf-8,' + encodeURIComponent(csvFormattedDataTable);
this.href = encodedUri;
this.download = 'table-data.csv';
this.target = '_blank';
});


I'm loading the charts api as follows:
google.load('maps', '3', {'other_params': 'key=' + key + '&libraries=drawing'});

google.setOnLoadCallback(function () {
google.charts.load('current', {packages: ['corechart']});
google.charts.setOnLoadCallback(function () {
precipitation.instance = new precipitation.App();
precipitation.instance.initVals();
});
});
Now if someone could give some additional advice on how to correctly load the api nowadays that'd be great :)

When I click the button I get the following error:


Line 60 being:
var csvFormattedDataTable = google.visualization.dataTableToCsv(this.chartData);

In my index.html I have both loaders:
<script type="text/javascript" src="https://www.google.com/jsapi"></script>
<script type="text/javascript" src="https://www.gstatic.com/charts/loader.js"></script>

Joep Kt

unread,
Jul 13, 2018, 5:59:45 AM7/13/18
to Google Visualization API
But in my IDE I downloaded the google visualization library for typehinting and it's not there. Neither can the method be found when I run the website.

Op woensdag 11 juli 2018 14:59:05 UTC+2 schreef Joep Kt:
Reply all
Reply to author
Forward
0 new messages