I am learning table in D3, my question is when to use ".select()":
For instance, when building circles:
var circles = svg.selectAll("circle")
.data(dataSet)
.enter()
.append("circle")
.attr("r", 2.5)
.attr("cx", function(d){ return d.x})
.attr("cy", function(d){ return d.y});
select circle (empty)-> append circle
but when I am building a table,
The following code directly appends the table, without select("table") first. Same for the "tr".
function tabulate(data, columns) {
var table = d3.select("#container").append("table"),
thead = table.append("thead"),
tbody = table.append("tbody");
// append the header row
thead.append("tr")
.selectAll("th")
.data(columns)
.enter()
.append("th")
.text(function(column) { return column; });
(code from "creating a table from csv")
Why won't the following code works?
function tabulate(data, columns) {
var table = d3.select("#container")
.select("table")
.append("table"),
thead = table.append("thead"),
tbody = table.append("tbody");
thanks in advance,