Mob*_*bie 23 javascript axis-labels d3.js
我用以下文字创建我的轴,但是标签的颜色没有正确改变; 文字保持黑色的颜色.有人知道为什么吗?
// create Axis
svg.selectAll(".axis")
.data(d3.range(angle.domain()[1]))
.enter().append("g")
.attr("class", "axis")
.attr("transform", function(d) { return "rotate(" + angle(d) * 180 / Math.PI + ")"; })
.call(d3.svg.axis()
.scale(radius.copy().range([-5, -outerRadius]))
.ticks(5)
.orient("left"))
.append("text")
.attr("y",
function (d) {
if (window.innerWidth < 455){
return -(window.innerHeight * .33);
}
else{
return -(window.innerHeight * .33);
}
})
.attr("dy", ".71em")
.attr("text-anchor", "middle")
.text(function(d, i) { return capitalMeta[i]; })
.attr("style","font-size:12px;")
.style("color","#DE3378"); <--------------- adding color attribute here...
Run Code Online (Sandbox Code Playgroud)
编辑 - 尝试使用以下代码为不同的轴标记不同的颜色,但这不能正常工作...
.style(function() {
for (var i = 0; i < unhealthyArray.length; i++) {
if ($.inArray(unhealthyArray[i], capitalMeta) != -1)
return "fill","red";
else
return "fill","black";
}
});
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
31162 次 |
| 最近记录: |