I want to specify a font size for the labels of a time axis created with D3. I've tried following this answer with this fiddle, but it doesn't seem to do anything. I've also tried
d3.selectAll(".xAxis>.tick>text")
.each(function(d, i){
d3.select(this).style("font-size",30);
});
to no avail. It can't be that hard...
I want to specify a font size for the labels of a time axis created with D3. I've tried following this answer with this fiddle, but it doesn't seem to do anything. I've also tried
d3.selectAll(".xAxis>.tick>text")
.each(function(d, i){
d3.select(this).style("font-size",30);
});
to no avail. It can't be that hard...
Share Improve this question edited May 23, 2017 at 10:31 CommunityBot 11 silver badge asked Jan 20, 2016 at 2:10 smcssmcs 2,0043 gold badges26 silver badges51 bronze badges 3 |2 Answers
Reset to default 19It turns out that a unitless number is technically not a valid CSS font size specifier and that it may depend on the browser whether it is ignored or not. Therefore, use
d3.select(this).style("font-size","30px");
instead of
d3.select(this).style("font-size",30);
Using below Code can set any styles of X label
const formatXLabel=()=>{
const parent = document.querySelector("."+ props.xAxis.class);
for(let x = 0; x<parent.children.length; x++) {
const ticks = parent.children.item(x);
if(ticks !==null && ticks.className.baseVal === 'tick') {
try {
const text = ticks.querySelector("text");
for (let sp in props.xAxis.labelStyles) {
text.style[sp.toString()] = props.xAxis.labelStyles[sp];
}
}catch (e){
console.log(e);
}
}
}
}
"60px"
instead of just60
. Gee – smcs Commented Jan 20, 2016 at 3:47