Knowledge Base Article
Hello! This script doesn't seem to work on stacked bar charts. On regular (non-stacked) bar charts it mostly works as expected, and I can adjust the number in the first line to adjust how much space there is. However, when I try the same script on stacked bar charts, it doesn't seem to have any effect, regardless of which number I put in the first line.
I bet it's due to the break-by splitting the bars into multiple stacked bars, and the script is only designed to shorten single bars. Is there a way to modify the script so it works on stacked bars instead?
- TriAnthony08-02-2024Admin
Hi fabricio_fta and Jake_Raz, please try this script below. This should work for:
- all Cartesian charts (Column, Bar, Line, and Area charts),
- negative values,
- single and multiple series (classic or stacked, using Break By or multiple values).
/*** This script is for increasing the y-axis max value by adding a percent of the highest value in the series to the y-axis max value. Similarly, in cases where the minimum value is negative, it also decreases the y-axis min value by subtracting a percent of the lowest value in the series from the y-axis min value. ***/ //Set the offset percent to add/subtract to/from the y-axis max/min value here var percentToAdd = 20; widget.on('processresult', function(se,ev){ var numberOfSeries = ev.result.series.length; var seriesData = []; var dataPoints = []; for(i=0; i < numberOfSeries; i++) { seriesData[i] = ev.result.series[i].data; var numOfDataPoints = seriesData[i].length; if(widget.subtype.includes('stacked')) { if(i==0) { for(j=0; j < numOfDataPoints; j++) { var dataToPush = seriesData[i][j].y; dataPoints.push(dataToPush); } } else { for(j=0; j < numOfDataPoints; j++) { dataPoints[j] = dataPoints[j] + seriesData[i][j].y; } } } else if(widget.subtype.includes('classic') || widget.subtype.includes('basic')) { for(j=0; j < numOfDataPoints; j++) { var dataToPush = seriesData[i][j].y; dataPoints.push(dataToPush); } } } var maxValue = Math.max.apply(Math, dataPoints); var minValue = Math.min.apply(Math, dataPoints); if(ev.result.yAxis[0].max <= 0) { ev.result.yAxis[0].max = 0 } else { ev.result.yAxis[0].max = maxValue * (1 + percentToAdd/100); } if(ev.result.yAxis[0].min >= 0) { ev.result.yAxis[0].min = 0; } else { ev.result.yAxis[0].min = minValue * (1 + percentToAdd/100); } })
- Jake_Raz08-06-2024ETL
This seems to work! Thanks!
- DRay08-01-2024Admin
Does this script help? https://community.sisense.com/t5/help-and-how-to/column-chart-prevent-bars-from-hiding-the-value-label-text/m-p/2715#M564