javascript - Insert child elements in d3.js -
i trying create table using d3.js, td elements not nesting inside tr.
this trying create:
<table> <tr> <td>name</td> <td>value</td> </tr> </table>
this i've tried:
var mytable = d3.select("#mytable") var mytablerow = mytable.selectall("tr") .data(mydata); mytablerow.enter() .append("tr") .insert("td", ":first-child") .html(function(d) { return d.name; }) .insert("td", ":first-child") .html(function(d) { return d.value; });
however, each td not nest inside tr.
var mytable = d3.select("#mytable") var mytablerow = mytable.selectall("tr") .data(mydata) .enter() .append("tr") mytablerow.append("td", ":first-child") .html(function (d) { return d.name; }) mytablerow.append("td", ":first-child") .html(function (d) { return d.value; });
var mydata = [ { name: 'a', value: 1 }, { name: 'b', value: 2 }, ] var mytable = d3.select("#mytable") var mytablerow = mytable.selectall("tr") .data(mydata) .enter() .append("tr") mytablerow.append("td", ":first-child") .html(function (d) { return d.name; }) mytablerow.append("td", ":first-child") .html(function (d) { return d.value; });
<script src="https://cdnjs.cloudflare.com/ajax/libs/d3/3.4.11/d3.min.js"></script> <table id="mytable"> </table>
Comments
Post a Comment