막대 차트에서 월에 따라 데이터를 업데이트하고 전환하려고합니다.d3.js의 가로 막 대형 차트를 업데이트하려고합니다.
저는 이것을 guide으로 사용했지만 어떻게 저의 예를 잘못 이해했는지 확신 할 수 없습니다. d3.js의 몇 가지 핵심적인 기본 사항을 놓치고 있다고 확신하지만 어디 있는지 모르겠습니다. 누군가가 나를 위해 그들을 가리킬 수 있다고 생각하니? 다음은 plnk 및 일부 코드입니다.
http://plnkr.co/edit/l0jQgzf2LHOatc1t8S5M?p=preview
function draw() {
updateData();
x.domain(group.map(function(d) {
return d.label;
}));
y.domain([0, 100]);
// add axis
svg.append("g")
.attr("class", "x axis")
.attr("transform", "translate(0," + height + ")")
.call(xAxis)
.selectAll("text")
.style("text-anchor", "end")
.attr("dx", "-.8em")
.attr("dy", "-.55em")
.attr("transform", "rotate(-90)");
svg.append("g")
.attr("class", "y axis")
.call(yAxis)
.append("text")
.attr("transform", "rotate(-90)")
.attr("y", 5)
.attr("dy", ".71em")
.style("text-anchor", "end")
.text("Value");
// Add bar chart
var bar = svg.selectAll("compareBar")
.data(group);
bar
.enter().append("rect")
.attr('x', function(d) {
return x(d.label);
})
.attr('y', function(d) {
return y(d.value);
})
.attr('width', x.rangeBand())
.attr('height', function(d) {
return height - y(d.value);
});
bar.exit().remove();
bar
.transition()
.duration(750)
.attr("y", function(d) {
return y(d.value);
})
.attr("height", function(d) {
return height - y(d.value);
});
svg.select(".y.axis").remove(); // << this line added
// Existing code to draw y-axis:
svg.append("g")
.attr("class", "y axis")
.call(yAxis)
.append("text")
.attr("transform", "rotate(-90)")
.attr("y", 6)
.attr("dy", ".71em")
.style("text-anchor", "end")
.text("value");
}
$("ul#months li a").click(function() {
$("#selectMonth").text($(this).text());
draw();
})
draw();
});
여기에 어떤 도움/조언을 사전에 .. 내가하지 백만 마일 떨어진 해요
감사를 기대하고있다!
내가 잘못가는 곳에 내가 볼 수 좋아 아, 감사합니다 설명! – alexc
안녕하세요, 두 번 덧글을 드려서 죄송합니다. (작성한) 내용을 조금 더 설명 할 수 있는지 궁금합니다.내가 이해할 수없는 부분 만 – alexc
처음에 그래프가로드 될 때 우리는 'draw (true);'함수를 호출하므로 create 플래그가 true가되고 모든 사각형과 축이 그려집니다. 업데이트시이 함수에서 'draw();'와 같은 create 플래그를 정의하지 않으므로 사각형과 축이 다시 그려지지 않습니다 ...이 경우 값을 업데이트하기 만하면됩니다. – Cyril