Created
October 9, 2013 04:13
-
-
Save pr4v33n/6896102 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// gviztablelog.js | |
// https://github.com/pr4v33n | |
// Adds a `gvizTableLog` function to window object. | |
// https://developers.google.com/chart/interactive/docs/reference#DataTable | |
(function() { | |
window.gvizTableLog = function(dataTable) { | |
var rowIndex = 0, tableData = [], columnIndex = 0, columnLabels = []; | |
while (columnIndex < dataTable.getNumberOfColumns()) { | |
columnLabels.push(dataTable.getColumnLabel(columnIndex) || | |
dataTable.getColumnId(columnIndex) || | |
columnIndex.toString()); | |
columnIndex++; | |
} | |
while (rowIndex < dataTable.getNumberOfRows()) { | |
var rowData = {}; | |
columnIndex = 0; | |
while (columnIndex < dataTable.getNumberOfColumns()) { | |
rowData[columnLabels[columnIndex]] = dataTable.getValue(rowIndex, columnIndex); | |
columnIndex++; | |
} | |
tableData.push(rowData); | |
rowIndex++; | |
} | |
console.table(tableData); | |
}; | |
})(); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment