0

I want to use HTML inside xAxes.ticks.callback, but when I do it:

xAxes: [{
  ticks: {
    callback: (tickValue, index, ticks) => {
      let tickValueNew = Math.abs(tickValue) + "%";
      tickValueNew += "<br>\n" + (100 - Math.abs(tickValue));
      return tickValueNew;
    },
  },
}]

It doesn't work it prints <br> on the page, how to change this?

uminder
  • 23,831
  • 5
  • 37
  • 72
Davidos
  • 419
  • 5
  • 17

1 Answers1

1

You cannot define HTML but in order to obtain multi-line tick labels, simply let your xAxes.ticks.callback function return an array.

In your case, this could look as follows:

xAxes: [{
  ticks: {
    callback: v => [Math.abs(v) + '%', 100 - Math.abs(v)]
  }
}]
uminder
  • 23,831
  • 5
  • 37
  • 72
  • Nice, but I need to set text color too on second label – Davidos Mar 15 '21 at 22:24
  • Please take a look at https://stackoverflow.com/a/61974056/2358409. It can easily be adapted in order to obtain multi-line tick labels where each line has its own text style and color. – uminder Mar 16 '21 at 03:41