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
13 - Data Warehouse
13 - Data Warehouse

@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_qbeeq
9 - Travel Pro
9 - Travel Pro

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_qbeeq - 

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
13 - Data Warehouse
13 - Data Warehouse

@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
13 - Data Warehouse
13 - Data Warehouse

@cartercjb ,

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

decimal place.jpg