Bar Chart

attr()
var dataset = [0, 1, 1, 2, 3, 5, 8, 13, 21, 34];
d3.select("#my3d").selectAll("div").data(dataset).enter().append("div").attr("class", "bar").style("height", function(d) {
	var barheight = d * 5;
	return barheight + "px";
});
 

Math.random()

產生隨機數字放入陣列;每次載入頁面會有不同結果

var dataset = [];
for (var i = 0; i < 25; i++) {
	var newNumber = Math.floor(Math.random() * 30);
	dataset.push(newNumber);
}
 
Go to top