Skip to content

Instantly share code, notes, and snippets.

@kbrammer
Created March 25, 2013 06:26
Show Gist options
  • Save kbrammer/5235255 to your computer and use it in GitHub Desktop.
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.
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