[英]D3: Day names on x-axis: Invalid value for <text> attribute x=“NaN”
我有一个D3区域图,显示了一段时间内的值。 沿我的x轴,我有1-7个与星期几相关的信息。 我想用mo,tu,we等替换这些,等等
this.g.selectAll(".xLabel")
.data(_this.x.ticks(6))
.enter().append("svg:text")
.attr("class", "xLabel")
.text(String)
.attr("x", function(d) { return _this.x(d) })
.attr("y", 0)
.attr("text-anchor", "end")
.attr("stroke", "white")
.attr("opacity", .5);
我认为可以通过更换来轻松实现
.attr("x", function(d) { return _this.x(d) })
与
.attr("x", function(d) { return _this.x(_this.arrDays[d]) })
(_this.arrDays是一个简单的[“ mo”,“ tu”,......]数组),但这给了我以下错误:
错误:属性x =“ NaN”的值无效
有人愿意透露一些信息吗?
排序:
this.g.selectAll(".xLabel")
.data(_this.x.ticks(6))
.enter().append("svg:text")
.attr("class", "xLabel")
.text(function(d) {return _this.arrDays[d-1]}) //changed this line
.attr("x", function(d) { return _this.x(d) })
.attr("y", "0")
.attr("text-anchor", "end")
.attr("stroke", "white")
.attr("opacity", .5);
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.