D3을 사용하여 barchart를 만들고 jquery를 사용하여 막대를 선택하고 있습니다. 나는 $ (this)와 console.log() 문을 사용하여 막대 (직사각형)를 선택했다고 생각하는 부분을 확인하지 못하는 문제가 발생했습니다. 그러나 특정 기능 (예 : 전환, 스타일)이 작동하는 데 문제가 있습니다. 오류 메시지는 기능이 아니라고 말합니다.
나는 아래에서 겪고있는 문제의 작은 예를 만들었습니다. barchart 대신 두 개의 직사각형 만 있습니다. 너비를 성공적으로 변경했지만 전환을 사용하여이 변경 사항을 부드럽게 처리 할 수 없으며 $ (this) .style을 사용하여 채우기 색상을 변경할 수도 없습니다.
도움 주셔서 감사합니다. 여기 내 코드가있다.
P. 이것은 내 첫 번째 StackOverflow 질문이므로이 질문을 다르게 받아야했는지 및/또는 내가 따르지 않은 규칙이 있는지 알려주십시오. 나는이 문제와 관련하여 며칠 동안 상당히 철저한 검색을 수행했으며 실제로 벽에 부딪쳤다. 다시 한 번 감사드립니다!
<body>
<svg width="1000" height="1000" id="this_svg">
<rect x="0" y="0" width="100" height="100" fill="blue" data-color="red"> </rect>
<rect x="0" y="100" width="100" height="100" fill="green" data-color="purple"></rect>
</svg>
<script>
$ (document).ready(function() {
$svg = $("#this_svg")
rcts = $svg.find("rect")
// This Works Fine
rcts.each(function() {
$(this).attr("width", "500")
});
// This breaks (see error message):
// Uncaught TypeError: $(...).transition is not a function
rcts.each(function() {
$(this).transition().duration(500).attr("width", "500")
});
//... and if this hadn't already broken, this next part would
// break instead (see error message):
// Uncaught TypError: $(...).style is not a function
rcts.each(
$(this).style("fill", function() {
return $(this).attr("data-color")
}));
});
</script>
</body>
질문 : 왜 당신은 당신의 코드가 D3를 사용하지 않는 경우 태그로'd3js'을해야합니까? Btw,'transition()'이 jQuery가 아닌 D3 함수이기 때문에이 오류가 발생합니다. –