私は D3 でテーブルを学習しています。私の質問は、「.select()」をいつ使用するかです。
たとえば、円を作成する場合:
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("table") を使用せずに、テーブルを直接追加します。「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; });
次のコードが機能しないのはなぜですか?
function tabulate(data, columns) {
var table = d3.select("#container")
.select("table")
.append("table"),
thead = table.append("thead"),
tbody = table.append("tbody");
前もって感謝します、