Created
March 25, 2013 06:26
-
-
Save kbrammer/5235255 to your computer and use it in GitHub Desktop.
Array.toDataTable() - Extends the array object to return a Google Visualization DataTable object. Depends on LINQjs.
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
Array.prototype.toDataTable = function () { | |
var results = {}; | |
results.cols = Enumerable.From(this[0]).Select(function (p) { | |
return { id: p.Key, label: p.Key, type: "string" }; | |
}).ToArray(); | |
results.rows = Enumerable.From(this).Select(function (c) { | |
return { c: Enumerable.From(results.cols).Select(function (i) { | |
return { v: c[i.id] }; | |
}).ToArray() | |
}; | |
}).ToArray(); | |
return results; | |
}; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment