Zivo
Posts: 2
Joined: Mon Jul 08, 2019 9:02 am

How to Convert column Data labels thousands to K?

Hello

I have this
Image

I want to format the labels above each column to have K in case its above thousands or M above millions
I saw some codes of Formatter but when added it to the datalabels property it loads with only zero or not at all

this is the code I found here

Code: Select all

formatter: function() {
          if ( this.value > 1000 ) return Highcharts.numberFormat( this.value/1000, 1) + "K";  // maybe only switch if > 1000
          return Highcharts.numberFormat(this.value,0);
        }
please, can you find me a solution?
Thank you
rafalS
Posts: 2665
Joined: Thu Jun 14, 2018 11:40 am

Re: How to Convert column Data labels thousands to K?

Hi Zivo,

Welcome to our forum and thanks for contacting us.

Are you looking for something like this?: https://jsfiddle.net/BlackLabel/wo0t4adj

Code: Select all

formatter: function() {
        if (this.y > 1000000) {
          return Highcharts.numberFormat(this.y / 1000, 3) + "M"
        } else if (this.y > 1000) {
          return Highcharts.numberFormat(this.y / 1000, 3) + "K";
        } else {
          return this.y
        }
      }
    },

Let me know if you have any further questions.

Best regards!
Rafal Sebestjanski,
Highcharts Team Lead
Zivo
Posts: 2
Joined: Mon Jul 08, 2019 9:02 am

Re: How to Convert column Data labels thousands to K?

Amazing thank you so much
just small correction in the million we also need to divide by million :)
rafalS wrote: Mon Jul 08, 2019 9:50 am Hi Zivo,

Welcome to our forum and thanks for contacting us.

Are you looking for something like this?: https://jsfiddle.net/BlackLabel/wo0t4adj

Code: Select all

formatter: function() {
        if (this.y > 1000000) {
          return Highcharts.numberFormat(this.y / 1000000, 3) + "M"
        } else if (this.y > 1000) {
          return Highcharts.numberFormat(this.y / 1000, 3) + "K";
        } else {
          return this.y
        }
      }
    },

Let me know if you have any further questions.

Best regards!
rafalS
Posts: 2665
Joined: Thu Jun 14, 2018 11:40 am

Re: How to Convert column Data labels thousands to K?

Ups, you're right :D
Rafal Sebestjanski,
Highcharts Team Lead
oneEyedGhoul
Posts: 2
Joined: Fri Dec 03, 2021 6:54 am

Re: How to Convert column Data labels thousands to K?

Can you help, how can we use same (5k, 10k,...) to csv.
I have formatted data on chart but when I am downloading .csv, it is giving actual numbers which I don't want.
Waiting for your response :)
oneEyedGhoul
Posts: 2
Joined: Fri Dec 03, 2021 6:54 am

Re: How to Convert column Data labels thousands to K?

I am able to format yaxis data to 250k instead of 250,000, but when I download csv from graph, I am getting 250000 instead of 250k.
could you help me with solution ?
mateusz.b
Posts: 2006
Joined: Tue Jul 13, 2021 11:34 am

Re: How to Convert column Data labels thousands to K?

Hello oneEyedGhoul,

Welcome to our forum and thanks for contacting us with your question!

In order to help your I need to take a look at your code. Please provide me with simplified demo of your chart. You can start here:
https://jsfiddle.net/BlackLabel/g96kt8jo/

Regards!
Mateusz Bernacik
Highcharts Developer

Return to “Highcharts Usage”