Change value axis format to read in millions

by MohamedGaafar » Tue Jun 21, 2016 7:53 pm

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
User avatar
MohamedGaafar
 
Posts: 22
Joined: Sat Jan 23, 2016 12:17 pm

by Dmitry Kozlov » Wed Jun 22, 2016 8:49 am

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) #
User avatar
Dmitry Kozlov
 
Posts: 129
Joined: Wed Nov 12, 2014 3:24 pm

by MohamedGaafar » Wed Jun 22, 2016 2:59 pm

Thanks a lot, works fine.
User avatar
MohamedGaafar
 
Posts: 22
Joined: Sat Jan 23, 2016 12:17 pm

by MohamedGaafar » Wed Jun 22, 2016 6:59 pm

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.
User avatar
MohamedGaafar
 
Posts: 22
Joined: Sat Jan 23, 2016 12:17 pm

by Dmitry Kozlov » Thu Jun 23, 2016 9:24 am

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?
User avatar
Dmitry Kozlov
 
Posts: 129
Joined: Wed Nov 12, 2014 3:24 pm

by MohamedGaafar » Thu Jun 23, 2016 12:27 pm

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.
User avatar
MohamedGaafar
 
Posts: 22
Joined: Sat Jan 23, 2016 12:17 pm

by Dmitry Kozlov » Fri Jun 24, 2016 9:43 am

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) #';
User avatar
Dmitry Kozlov
 
Posts: 129
Joined: Wed Nov 12, 2014 3:24 pm

by MohamedGaafar » Fri Jun 24, 2016 11:21 am

Thanks a lot, works fine.
User avatar
MohamedGaafar
 
Posts: 22
Joined: Sat Jan 23, 2016 12:17 pm


Return to Dashboard Designer for SharePoint 2013