'Formatting Highcharts labels with a callback function (Formatter)

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.



Solution 1:[1]

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
        }
      },

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 sebdoy