Showing results for 
Search instead for 
Did you mean: 

Bar Chart - Add Percentage to the Value Label

Sisense Team Member
Sisense Team Member

When creating a column chart you might want to add a percentage value next to the actual value

Add the following script to your widget:

widget.on('processresult', function(widget,result) { 
result.result.plotOptions.series.dataLabels.formatter = function() {
total = 0 { total += datapoint.y })

percent = (100 * this.y) / (total);
percent = percent.toFixed(1);

return this.y + '<br/>(' + percent + '%)'
Before After
Ophir_Buchman_0-1650452574643.png Ophir_Buchman_1-1650452595480.png

7 - Data Storage
7 - Data Storage

Thank you for producing this code.  This is a feature I have been trying to figure out for a while.  Can you please provide some additional detail? I am a user with minimal script/coding experience.  Is this script inserted into the script editor or directly into the sql code for the widget?  Also, are there variables within this code that need to be changed for the specific widget data it is inserted into?  Thank you.