cancel
Showing results for
Did you mean:

# Dynamic Decimal Points

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)

1 ACCEPTED SOLUTION
13 - Data Warehouse

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)

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

6 REPLIES 6
9 - Travel Pro

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

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".

13 - Data Warehouse

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)

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.

13 - Data Warehouse

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

Community Toolbox

Developers Group:

Product Feedback Forum: