Google spreadsheet debug
by Gert Vaartjes
HTML
<script src="https://code.highcharts.com/highcharts.js"></script>
<script src="https://code.highcharts.com/modules/data.js"></script>
JavaScript
/**
* Parse a Google spreadsheet.
*/
function parseGoogleSpreadsheet(options) {
var //data = this,
//options = this.options,
googleSpreadsheetKey = options.googleSpreadsheetKey,
//chart = this.chart,
// use sheet 1 as the default rather than od6
// as the latter sometimes cause issues (it looks like it can
// be renamed in some cases, ref. a fogbugz case).
worksheet = options.googleSpreadsheetWorksheet || 1,
startRow = options.startRow || 0,
endRow = options.endRow || Number.MAX_VALUE,
startColumn = options.startColumn || 0,
endColumn = options.endColumn || Number.MAX_VALUE,
refreshRate = (options.dataRefreshRate || 2) * 1000,
each = Highcharts.each;
if (refreshRate < 4000) {
refreshRate = 4000;
}
/*
* Fetch the actual spreadsheet using XMLHttpRequest
*/
function fetchSheet(fn) {
var url = [
'https://spreadsheets.google.com/feeds/cells',
googleSpreadsheetKey,
worksheet,
'public/values?alt=json'
].join('/');
Highcharts.ajax({
url: url,
dataType: 'json',
success: function(json) {
console.log('from Google', json);
fn(json);
if (options.enablePolling) {
setTimeout(function() {
fetchSheet(fn);
}, options.dataRefreshRate);
}
},
error: function(xhr, text) {
return options.error && options.error(text, xhr);
}
});
}
if (googleSpreadsheetKey) {
delete options.googleSpreadsheetKey;
fetchSheet(function(json) {
// Prepare the data from the spreadsheat
var columns = [],
cells = json.feed.entry,
cell,
cellCount = (cells || []).length,
colCount = 0,
rowCount = 0,
...