d3 시각화에 드롭 다운 메뉴를 추가하려고합니다. 문제는 eventlistener가 옵션을 선택할 때 호출되지 않는다는 것입니다. 또한 선택한 옵션 값에 어떻게 액세스 할 수 있습니까? 다음은 당신은 select
요소가 아닌 option
요소에 .on("change")
를 추가 할 필요가 ... Thankxd3.js를 사용하여 드롭 다운 메뉴 추가
13
A
답변
32
d3.text("uniqueTeams.php",function(json){
var dd=JSON.parse(json);
var b= d3.select("#s4").select("#shru");
var u=b.append("select");
var t=u.selectAll("option").data(dd).enter().append("option")
.attr("value",function(d){return d.teamShotID;})
.text(function(d){return d3.select(this).node().__data__.teamShotID;});
t.on("change",change);
});
function change(value)
{
console.log("team",value);
}
change();
내 코드의 조각이다.
var select = d3.select("#shru").append("select").on("change", change),
options = select.selectAll('option').data(dd); // Data join
// Enter selection
options.enter().append("option").text(function(d) { return d.teamShotID; });
현재 선택된 option
인덱스
select
selectedIndex
요소라는 속성을 유지한다.
Selections are arrays, so elements can be accessed directly (e.g., selection[0][0]
). 나는 또한이 대안 구문을 포함하려면, 가독성과 희망 당신은 위의 코드를 이해하는 데 도움이 :
function change() {
var selectedIndex = select.property('selectedIndex'),
data = options[0][selectedIndex].__data__;
}
편집 : 각 option
요소는 데이터 __data__
라는 속성에 저장, 바인드 것이다
function change() {
var si = select.property('selectedIndex'),
s = options.filter(function (d, i) { return i === si }),
data = s.datum();
}
0
희망 ...
var dispatch = d3.dispatch("load", "countrychange");
d3.csv("data/ERSreputationBlocked.csv",type, function (error, country) {
if (error) throw error;
var countryById = d3.map();
country.forEach(function (d) { countryById.set(d.id, d); });
dispatch.load(countryById);
dispatch.countrychange(countryById.get("PH"));
//console.log(country);
});
dispatch.on("load.menu", function(countryById) {
var select = d3.select("body")
.append("div")
.append("select")
.on("change", function() { dispatch.countrychange(countryById.get(this.value)); });
select.selectAll("option")
.data(countryById.values())
.enter().append("option")
.attr("value", function (d) { return d.id; })
.text(function (d) { return d.Country; });
dispatch.on("countrychange.menu", function (country) {
select.property("value", country)
//loading the value based on the selected data
var svg1 = d3.select("body").append("svg1")
.attr("width", width)
.attr("height", height)
//end of selection
console.log(country);
});
});
//end of drop down
function type(d) {
d.total = d3.sum(d.value, function (k) { return d[k] = +d[k]; });
return d;
}
관련 문제
- 1. jquery로 드롭 다운 메뉴 추가
- 2. jquery를 사용하여 드롭 다운 메뉴
- 3. jQuery를 드롭 다운 메뉴 스크립트에 hoverIntent 추가
- 4. jquery 동적 드롭 다운 메뉴 - 추가 문제
- 5. mvc3의 드롭 다운 메뉴
- 6. 은 드롭 다운 메뉴
- 7. html5의 드롭 다운 메뉴
- 8. 보기의 ToolBarManager에 드롭 다운 메뉴 추가
- 9. CRM 2011 리본에 드롭 다운 메뉴 추가
- 10. 버튼 클릭 - 드롭 다운 메뉴 추가 8
- 11. CMFC 툴바에 드롭 다운 메뉴 버튼 추가
- 12. HTML 드롭 다운 메뉴
- 13. 탐색 메뉴 드롭 다운
- 14. CSS 드롭 다운 메뉴
- 15. Wordpress의 드롭 다운 메뉴
- 16. 드롭 다운 메뉴 도움 필요
- 17. 안드로이드의 드롭 다운 메뉴
- 18. 드롭 다운 메뉴 만들기
- 19. PHP 드롭 다운 메뉴
- 20. Imacros 드롭 다운 메뉴
- 21. CSS 드롭 다운 메뉴
- 22. JQuery와 드롭 다운 메뉴
- 23. Dreamweaver 드롭 다운 메뉴
- 24. 오른쪽 드롭 다운 메뉴
- 25. jQuery를 드롭 다운 메뉴,
- 26. android의 드롭 다운 메뉴
- 27. JMenuBar없이 드롭 다운 메뉴
- 28. jquery 드롭 다운 메뉴
- 29. 필터 드롭 다운 메뉴
- 30. ClickEvent가있는 드롭 다운 메뉴