1
我在圖中有一個下拉列表來選擇用戶想要顯示的點。 A是綠色的。 B是黃色的,這是我的默認選項。當情節第一次加載時,我只想要在情節中顯示的黃色點。但這裏顯示了數據中的所有要點。誰能告訴我如何解決它?如何設置默認選項d3.js
var defaultOption = ["B"];
var dropDown = d3.select("#filter").append("select")
.attr("type", "AB")
.attr("class","list");
var options = dropDown.selectAll("option")
.data(d3.map(data, function(d){return d.type;}).keys())
.enter()
.append("option")
.property("selected", function(d){
return d == defaultOption;})
.text(function (d) { return d; })
.attr("value", function (d) { return d; });
dropDown.on("change", function() {
var selected = this.value;
displayOthers = this.checked ? "inline" : "none";
display = this.checked ? "none" : "inline";
svg.selectAll(".circles")
.filter(function(d) {return selected != d.type;})
.attr("display", displayOthers);
svg.selectAll(".circles")
.filter(function(d) {return selected == d.type;})
爲'dropDown.node()'它返回什麼?對於'selection.node()'它聲明它將返回當前選擇中的第一個非空元素。從控制檯日誌中顯示_