d3.js - D3 cross tabulation HTML table -
i'm trying create d3 cross tabulation html table (there more interactive features, first step) based on json data. can populate horizontal table header, having trouble vertical headers , data fields.
the table should following:
my code far (jsfiddle here) is:
var nested = d3.nest() .key(function(d) { return d._id.env; }) .entries(data.result); console.log(nested); var table = d3.select("#table") .append("table") .style("border-collapse", "collapse") .style("border", "2px black solid"); var thead = table.append("thead"); thead.append("tr") .selectall("th") .data(nested) .enter().append("th") .text(function(d) { return d.key; }); var tbody = table.append("tbody"); var tr = tbody.selectall("tr") .data(nested.values) // not sure how .enter().append("tr"); tr.selectall("td") .data(function(d) { console.log(d); return d; }) .enter().append("td") .text(function(d, i) { console.log(d[i]); return d; });
the raw data in following format:
{ "result" : [ { "_id" : { "month" : 5, "day" : 6, "year" : 2014, "env" : "a" }, "rulescore" : 83.25, "jsperpage" : 12, "cssperpage" : 4, "imagesperpage" : 7.75 }, { "_id" : { "month" : 5, "day" : 6, "year" : 2014, "env" : "b" }, "rulescore" : 83, "jsperpage" : 12, "cssperpage" : 4, "imagesperpage" : 10 }, { "_id" : { "month" : 5, "day" : 6, "year" : 2014, "env" : "c" }, "rulescore" : 83, "jsperpage" : 12, "cssperpage" : 5, "imagesperpage" : 10, }, { "_id" : { "month" : 5, "day" : 6, "year" : 2014, "env" : "d" }, "rulescore" : 83.08333333333333, "jsperpage" : 12, "cssperpage" : 6, "imagesperpage" : 9.25 } ], "ok" : 1 }
i'm guessing pretty simple, can't head around - thanks!
Comments
Post a Comment