Ad

D3: Change Font Size Of Axis Labels

- 1 answer

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...

Ad

Answer

It 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);
Ad
source: stackoverflow.com
Ad