question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Change an Axis's label font-size

See original GitHub issue

How can you change an Axis’s label font-size?

According to the docs (https://github.com/hshoff/vx/tree/master/packages/vx-axis), the “label” attribute is a string value.

When the label is rendered, the <text> element has several attributes that I haven’t specified:

Code to produce the Axis:

<AxisBottom
        left={50}
        scale={xAxisScale}
        top={yMax + margin.top}
        stroke='gray'
        tickStroke='gray'
        label="My Amazing Customized Label!"
        tickLabelComponent={(
          <text
            fill='gray'
            fontSize={11}
            textAnchor="middle"
          />
        )}
      />

(as an aside, tickLabelComponent isn’t mentioned in Axis’s docs either, I just saw it in an example)

Rendered label SVG:

<text 
  text-anchor="middle" 
  font-family="Arial" 
  font-size="10"
  fill="black" 
  x="575" 
  y="37">
  My Amazing Customized Label!
</text>

Issue Analytics

  • State:closed
  • Created 6 years ago
  • Comments:6 (2 by maintainers)

github_iconTop GitHub Comments

1reaction
williastercommented, Jul 25, 2017

thanks 😃 If in doing so you have thoughts / comments on the api let us know. I’ve thought about:

  1. keep it as is with different behavior for a string vs a component.

  2. we could make this more clear by adopting the labelComponent prop name of the lower-level Axis component that AxisTop/Right/Bottom/Left wrap. that means if you pass a string we render is as-is and makes it harder to simply pass in a string and get some styles like you do now.

  3. you could make this two props: label that is only a string and labelComponent which specifies the component to use to wrap it.

none of these let you easily tweak a single value like font-size without specifying all of the other styles on the component. I’d probably vote for 2 and fix this issue with a better Label or Text component that would add default styles for you and let you override one or all of them easily 🤔

1reaction
donpinkuscommented, Jul 25, 2017

Thanks!

Trying now, will post updated code (to serve as a reference until docs are updated) then will close.

Read more comments on GitHub >

github_iconTop Results From Across the Web

How do I set the figure title and axes labels font size?
I want to specify font sizes for the figure title and the axis labels. I need all three to be different font sizes,...
Read more >
How to change chart axis labels' font color and size in Excel?
Just click to select the axis you will change all labels' font color and size in the chart, and then type a font...
Read more >
Changing font size of all axes labels - MATLAB Answers
Changing font size of all axes labels. ... I wonder what's not working for the label font size when axis font size is...
Read more >
Change Font Size of ggplot2 Plot in R | Axis Text, Main Title ...
How to modify font sizes of ggplot2 graphics in R - 5 programming examples - Change font size of axes, main title &...
Read more >
How to change the size of axis labels in Matplotlib?
If we want to change the font size of the axis labels, we can use the parameter “fontsize” and set it your desired...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found