[英]Simple d3 bar graph doesn't show up
This is the simple bar graph that I am trying out. 这是我正在尝试的简单条形图。 But nothing is showing up.
但是什么都没有出现。
var data = [4, 8, 15, 16, 23, 42];
var chart = d3.select("body").append("svg:svg")
.attr("class", "chart")
.attr("width", 420)
.attr("height", 20 * data.length);
var x = d3.scale.linear().domain([0, d3.max(data)]).range([0, 420]);
chart.selectAll("svg:rect")
.data(data)
.enter().append("svg:rect")
.attr("y", function(d, i) { return i * 20; })
.attr("width", x)
.attr("height", 20)
If I use rect
instead of svg:rect
the rects get created as I can see in console but I cannot see it in browser. 如果我使用
rect
而不是svg:rect
那么将在控制台中看到创建的rects,但是在浏览器中看不到它。
You might have to add some CSS to fill/colour the rectangles. 您可能需要添加一些CSS来填充/着色矩形。 You can also set this using
.style("fill", "red")
for example. 例如,您也可以使用
.style("fill", "red")
进行设置。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.