Skip to content

How can I set the max-width to each data.labels? #10116

Answered by LeeLenaleee
Shahzayb asked this question in Q&A
Discussion options

You must be logged in to vote

You could use a custom tick callback for the x axis to achieve this:

x: {
  ticks: {
    callback: function(val, index, ticks) {
      const tickText = this.getLabelForValue(val);

      return tickText.length > 10 ?
        `${tickText.substring(0, 9)}...` :
        tickText;
    }
  }
},

https://codesandbox.io/s/muddy-snow-jgg5m?file=/src/App.js

Replies: 1 comment 2 replies

Comment options

You must be logged in to vote
2 replies
@Shahzayb
Comment options

@LeeLenaleee
Comment options

Answer selected by Shahzayb
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
2 participants