cancel
Showing results for 
Search instead for 
Did you mean: 

Dynamic Decimal Points

cartercjb
10 - ETL
10 - ETL

Hello Sisense Community!

Is anyone aware of a method to dynamically round data labels so that: 

  1. Any value >= 1000.00 shows two decimal points (green in the screenshot)
  2. Any value < 1000.00 shows 0 decimal points (yellow in the screenshot)

cartercjb_0-1642198178458.png

 

1 ACCEPTED SOLUTION

harikm007
12 - Data Integration
12 - Data Integration

@cartercjb 

I think there are 2 solution : 

1. You can choose automatic rounding in 'Format Number' window. It will automatically remove '.00' from values (here we cannot control number of digits after decimal point as it is deciding decimal places dynamically)

automatic rounding.jpg 

2. Here is a script for this purpose : 

//Apply rounding in datalabel
widget.on('processresult', function(se,ev){
	
	ev.result.plotOptions.series.dataLabels.formatter = function(){
		return this.y < 1000 ? this.y.toFixed(0) : ev.result.series[0].mask(this.y)
	}
	
})

//applying rounding in tooltip
widget.on('beforedatapointtooltip', function(se,ev){
	
	if(ev.context.pointScope.y < 1000)
		ev.context.points[0].value = ev.context.pointScope.y.toFixed(0)
		
})

(Note : percentage/currency symbol will not work with this script)

 

Thanks,

-Hari

View solution in original post

6 REPLIES 6

alek
8 - Cloud Apps
8 - Cloud Apps

Hey!
You can achive this using simple widget script, please refer to this one:

widget.on("beforeviewloaded", function (se, ev) {

    ev.options.plotOptions.series.dataLabels.formatter = function () {
        let y = this.y

        if (y >= 1000) {
            y = y.toFixed(2);

        } else {
			y = y.toFixed(); 
		}
        return y
    }
})

 If you have any more questions feel free to reach out! We’re always here to help!

Hi @alek - 

Thanks for your suggestion and feedback! This script is super close, but off just a little when the values > 1000. It is reading as "1313.00" instead of "1.31 k". 

cartercjb_0-1642427148449.png

 

harikm007
12 - Data Integration
12 - Data Integration

@cartercjb 

I think there are 2 solution : 

1. You can choose automatic rounding in 'Format Number' window. It will automatically remove '.00' from values (here we cannot control number of digits after decimal point as it is deciding decimal places dynamically)

automatic rounding.jpg 

2. Here is a script for this purpose : 

//Apply rounding in datalabel
widget.on('processresult', function(se,ev){
	
	ev.result.plotOptions.series.dataLabels.formatter = function(){
		return this.y < 1000 ? this.y.toFixed(0) : ev.result.series[0].mask(this.y)
	}
	
})

//applying rounding in tooltip
widget.on('beforedatapointtooltip', function(se,ev){
	
	if(ev.context.pointScope.y < 1000)
		ev.context.points[0].value = ev.context.pointScope.y.toFixed(0)
		
})

(Note : percentage/currency symbol will not work with this script)

 

Thanks,

-Hari

Thanks, @harikm007! This script worked well! Fortunately, I do not need symbols for this metric. But, is there no way to append a symbol on top of the script you provided?

Thanks,

Carter

@harikm007  Hari - 

Is this script specific to an unstacked chart? I tried adding this to a stacked chart and there was no change to the data labels. 

cartercjb_0-1643049626452.png

 

harikm007
12 - Data Integration
12 - Data Integration

@cartercjb ,

Please check whether 2 decimal places is selected in format window.

decimal place.jpg

 

Voice of Customer
Impact Business Intelligence (BI) and Analytics Market Research

Click Here & Complete Dresner's Wisdom of Crowds® Market Study Survey Today!

Community Toolbox

Recommended quick links to assist you in optimizing your community experience:

Need additional support?:

Community Support Request

Don't miss out:

Earn a BETA Launch Challenge Badge!