## Change value axis format to read in millions

Hi,
I have a sales revenue chart with values in millions that currently display as QAR 1,000,000, QAR 2,000,000 etc. with incremental step of one million. The problem is it's taking too much space from the chart width to display all those zeros on the y-axis, so i wonder if there's a way to format values so that they display like QAR 1M, QAR 2M, etc. instead.

Thanks

MohamedGaafar

Posts: 22
Joined: Sat Jan 23, 2016 12:17 pm

## Re: Change value axis format to read in millions

Hi,
Put the following code into Dashboard -> Advanced tab.

Code: Select all
`window.FormatLongNumber = function(value) {  if(value == 0) {    return 0;  }  else  {      // hundreds      if(value <= 999){        return value;      }      // thousands      else if(value >= 1000 && value <= 999999){        return (value / 1000) + 'K';      }      // millions      else if(value >= 1000000 && value <= 999999999){        return (value / 1000000) + 'M';      }      // billions      else if(value >= 1000000000 && value <= 999999999999){        return (value / 1000000000) + 'B';      }      else        return value;  }}`

Then, set the template property of the appropriate axis in:
#= FormatLongNumber(value) #

Dmitry Kozlov

Posts: 129
Joined: Wed Nov 12, 2014 3:24 pm

## Re: Change value axis format to read in millions

Thanks a lot, works fine.

MohamedGaafar

Posts: 22
Joined: Sat Jan 23, 2016 12:17 pm

## Re: Change value axis format to read in millions

I wonder how would i do the same thing for a linear gauge, i tried the same code for one linear gauge chart, however it didn't work out.

MohamedGaafar

Posts: 22
Joined: Sat Jan 23, 2016 12:17 pm

## Re: Change value axis format to read in millions

A Linear gauge displays a single value. So, how do you want to bind a drop-down to a linear gauge? Do you want to visualize a field value of the selected item?

Dmitry Kozlov

Posts: 129
Joined: Wed Nov 12, 2014 3:24 pm

## Re: Change value axis format to read in millions

I have a vertical linear gauge showing the actual sales vs target, where the ranges represent the target and the green bar indicating the actual sales as opposed to the target ranges. and values of the ranges are all in millions with 6 zeros, so i want the values to read M instead of 6 zeros likewise i did for other charts.

MohamedGaafar

Posts: 22
Joined: Sat Jan 23, 2016 12:17 pm

## Re: Change value axis format to read in millions

Hi,
define the same function (FormatLongNumber)

and insert the following code into preRender handler in Dashboard -> Advanced tab:
Code: Select all
`config.scale.labels.template = '#= FormatLongNumber(value) #';`

Dmitry Kozlov

Posts: 129
Joined: Wed Nov 12, 2014 3:24 pm

## Re: Change value axis format to read in millions

Thanks a lot, works fine.

MohamedGaafar

Posts: 22
Joined: Sat Jan 23, 2016 12:17 pm