[英]Error: Invalid value for <rect> attribute width=“NaN” 6d3.v3.min.js:1 Error: Invalid value for <text> attribute x=“NaN”
bar.append("rect")
.attr("width", x)
.attr("height", barHeight - 1);
bar.append("text")
.attr("x", function(d) { return x(d) - 3; })
.attr("y", barHeight / 2)
.attr("dy", ".35em")
.text(function(d) { return d; });
Hi, I am new to charting with D3. 嗨,我是D3图表的新手。 Now I am trying out many tutorials from d3.com. 现在,我正在尝试d3.com提供的许多教程。 Now I get the 2 errors displayed in the title when trying to make a svg bar chart. 现在,当尝试制作svg条形图时,标题中显示了2个错误。 Is there anyone who could help me? 有谁可以帮助我吗?
I ran into a similar problem when I was setting my width with a value that was NaN
. 我将宽度设置为NaN
时遇到了类似的问题。 You need to check that you are setting the x
variable correctly. 您需要检查是否正确设置了x
变量。 Try pasting console.log(x)
above this line: 尝试将console.log(x)
粘贴到此行上方:
.attr("width", x)
and checking your console in your browser's dev tools. 并在浏览器的开发工具中检查控制台。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.