admin管理员组文章数量:1387305
Here is my code. I want to change the color of the actual axis line from black to grey.
var xAxisCall = d3.axisBottom(x);
g.append("g")
.attr("class", "x axis")
.attr("transform", "translate(0, " + height + ")")
.call(xAxisCall)
.selectAll("text")
.attr("y", "10")
.attr("x", "-5")
.attr("text-anchor", "end")
.attr("transform", "rotate(-40)")
.style("fill", "#999999");
Here is my code. I want to change the color of the actual axis line from black to grey.
var xAxisCall = d3.axisBottom(x);
g.append("g")
.attr("class", "x axis")
.attr("transform", "translate(0, " + height + ")")
.call(xAxisCall)
.selectAll("text")
.attr("y", "10")
.attr("x", "-5")
.attr("text-anchor", "end")
.attr("transform", "rotate(-40)")
.style("fill", "#999999");
Share
Improve this question
asked Jan 18, 2019 at 19:43
Art3misArt3mis
1091 silver badge8 bronze badges
1
-
1
add a CSS style that address the
path
in theg
:.x.axis path { stroke:red;}
– rioV8 Commented Jan 18, 2019 at 20:35
1 Answer
Reset to default 7If you're using D3 v5 (and possibly v4) the default styling is now embedded at the element level, which saves you having to specify it yourself in CSS. One way to get over this is to override it with CSS's !important flag.
.x.axis line {
stroke: gray !important;
}
Alternatively re-apply it to the elements after calling the axis using d3:
d3.selectAll(".x.axis line")
.style("stroke","gray");
A little finessing may be required, but the principle should work.
本文标签: javascriptHow to change the color of a d3js axis lineStack Overflow
版权声明:本文标题:javascript - How to change the color of a d3.js axis line - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1744526644a2610783.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论