사이트에서 다음 코드를 수정하여 원래 데이터와 업데이트 된 데이터를 모두 그래프에 표시하려고합니다. 업데이트 된 데이터를 다른 색상으로 유지하고 원래 데이터를 표시하고 변경 사항을 확인합니다. 누구든지 저에게 오류를 지적 할 수 있습니다. 내가 d3.selectAl를 사용하여 원본 데이터의 제어를 얻을 수 있다면막 대형 차트의 원래 데이터 및 업데이트 된 데이터 표시
<title>d3 example</title>
<style>
.original{
fill: rgb(7, 130, 180);
}
.updated{
fill: rgb(7,200,200);
}
</style>
는
<script type="text/javascript" src="https://ajax.googleapis.com/ajax/libs/jquery/1.7.2/jquery.min.js"></script>
<script type="text/javascript" src="http://d3js.org/d3.v2.min.js"></script>
<script type="text/javascript">
// Suppose there is currently one div with id "d3TutoGraphContainer" in the DOM
// We append a 600x300 empty SVG container in the div
var chart = d3.select("#d3TutoGraphContainer").append("svg").attr("width", "600").attr("height", "300");
// Create the bar chart which consists of ten SVG rectangles, one for each piece of data
var rects = chart.selectAll('rect').data([1 ,4, 5, 6, 24, 8, 12, 1, 1, 20])
.enter().append('rect')
.attr("stroke", "none")
//.attr("fill", "rgb(7, 130, 180)")
.attr('class','original')
.attr("x", 0)
.attr("y", function(d, i) { return 25 * i; })
.attr("width", function(d) { return 20 * d; })
.attr("height", "20");
// Transition on click managed by jQuery
rects.on('click', function() {
// Generate randomly a data set with 10 elements
var newData = [1,2,3,4];
//for (var i=0; i<10; i+=1) { newData.push(Math.floor(24 * Math.random())); }
var newRects = d3.selectAll('rects.original');
newRects.data(newData)
.transition().duration(2000).delay(200)
.attr("width", function(d) { return d * 20; })
//.attr("fill", newColor);
.attr('class','updated');
});
</script>
나는 알고 싶어 l ('rects.original')