d3动态生成条形图,效果如下:
WeChatSight3.gif
var dataset=[];
var nextdata = function(x){
return 20 + x*x;
};
var pushdata = function(){
dataset.push(nextdata);
return dataset;
};
var _svg = d3.select("body")
.append("svg")
.attr("width","400")
.attr("height","800");
function drawRect(){
_svg.selectAll("rect")
.data(pushdata)
.enter()
.append("rect")
.attr("x","20")
.attr("y",function(d,i){
return 20+20*i+30*i;
})
.attr("width",function(d,i){
return d(i);
})
.attr("height","20")
.style("fill","blue");
}
setInterval(function(){
drawRect();
},2*100)
网友评论