var width = 300; //畫布的寬度
var height = 300; //畫布的高度
var svg = d3.select("#app") //選擇文檔中的元素
.append("svg") //添加一個svg元素
.attr("width", width) //設(shè)定寬度
.attr("height", height); //設(shè)定高度
var dataset = [ 250 , 210 , 170 , 130 , 90 ];
var rectHeight = 25; //每個矩形所占的像素高度(包括空白)
svg.selectAll("rect")
? .data(dataset)
? .enter()
? .append("rect")
? .attr("x",20)
? .attr("y",function(d,i){
return i * rectHeight;
? })
? .attr("width",function(d){
? return d;
? })
? .attr("height",rectHeight-2)
? .attr("fill","steelblue");