我知道如何创建单选按钮以在不使用d3 js的情况下动态显示。但是如何使用d3创建单选按钮的标签文本?创建后,如何将它们添加到单选按钮?
答案 0 :(得分:2)
var shapeData = ["Triangle", "Circle", "Square", "Rectangle"],
j = 3; // Choose the rectangle as default
// Create the shape selectors
var form = d3.select("body").append("form");
labels = form.selectAll("label")
.data(shapeData)
.enter()
.append("label")
.text(function(d) {return d;})
.insert("input")
.attr({
type: "radio",
class: "shape",
name: "mode",
value: function(d, i) {return i;}
})
.property("checked", function(d, i) {return i===j;});