svg에 텍스트 요소를 추가하려고하지만 그 중 3 개를 추가하려고합니다. 바인드 메서드를 사용하여 실제 데이터를 추가하기 시작 했으므로 그 것이 문제라고 생각했습니다. 그러나 데이터를 제거하고 데이터를 하드 코딩하는 것은 도움이되지 못했습니다. "d"는 37 개의 필드가있는 객체입니다.추가 텍스트 요소를 추가하는 eventListener
function handleMouseOver(d, i) {
// Add interactivity
let myLabel = d['ROBBERY'];
var svg = d3.select("svg");
// Use D3 to select element, change color and size
var text = svg.selectAll("text")
.data(d['ROBBERY'])
.enter()
.append("text")
.attr("id",i);
var textLabels = text
.attr("x", w-50)
.attr("y", h-30)
.text(function() {
return myLabel;
})
.attr("font-family", "sans-serif")
.attr("font-size", "20px")
.attr("fill", "red");
// Specify where to put label of text
} ...
.on("mouseover", handleMouseOver)
페이지에 다른 텍스트 요소 요소가 없습니다.
나는이 3 수 :
<text id="5" x="750" y="170" font-family="sans-serif" font-size="20px" fill="red">951</text>
<text id="5" x="750" y="170" font-family="sans-serif" font-size="20px" fill="red">951</text>
<text id="5" x="750" y="170" font-family="sans-serif" font-size="20px" fill="red">951</text>
'd [ 'ROBBERY']'의 값은 무엇입니까? –
조금 청소했는데 이벤트 핸들러에 괄호가 있습니다. 그것은 무슨 일이 일어나고 있는지에 영향을 미치지 않았지만 질문에 대답하기 위해 d [ 'ROBBERY']의 값은 951입니다. – mike628