javascript - Export Data from dc.js dataTable into CSV -
i have data table done dc.js , crossfilter.js, , want export table csv file..
datatable.width(960).height(800) .dimension(by_id) .group(function(d) { return "" }) .size(data.length) .columns([ function(d) { return d.id; }, function(d) { return d.name; }, function(d) { return d.gender; }, function(d) { return parsefloat(d.gpa).tofixed(2); }, function(d) { return parsefloat(d.major_gpa).tofixed(2); }, function(d) { return parsefloat(d.math_gpa).tofixed(2); }, function(d) { return parsefloat(d.english_gpa).tofixed(2); }, function(d) { return parsefloat(d.science_gpa).tofixed(2); }, function(d) { return parsefloat(d.humanities_gpa).tofixed(2); } ]) .sortby(function(d){ return d.id; }) .order(d3.ascending);
this common request, i've added example using filesaver.js. (there other ways to download browser, 1 i'm familiar with.)
http://dc-js.github.io/dc.js/examples/download-table.html
the key fetch data table's dimension using dimension.top(infinity)
. can format using d3.csv.format
, download using preferred method. here, filesaver uses blob
s mechanism:
var blob = new blob([d3.csv.format(namedim.top(infinity))], {type: "text/csv;charset=utf-8"}); saveas(blob, 'data.csv');
Comments
Post a Comment