Home > Net >  Formatting Highcharts labels with a callback function (Formatter)
Formatting Highcharts labels with a callback function (Formatter)

Time:04-12

I'm trying to remove the last 3 numbers and replace it with a string 'k' on one labelled chart axis.

Here's what I've tried so far:

    labels: {
      formatter: function () {
        if (this.value >= 1000) {
          return this.value.slice(0, -3)   'k'
        } else {
          return this.value
        }

Doing it this way gives me an error.

CodePudding user response:

Found my mistake, here's how I fixed it:

   formatter: function () {
        if (this.value >= 1000) {
          return this.value.toString().slice(0, -3)   'k';
        } else {
          return this.value
        }
      },
  • Related