Adjust Chart Unit Spacing To Keep Consistent Bar Width

mwilliamsmwilliams BIRT Guru
edited November 2013 in DevShare Downloads
This example shows how script can be used to adjust the unit spacing of the bars so that the width of them stays consistent through all groups. The calculation depends on knowing the maximum number of bars in any given chart. If you don't know this, you can probably dynamically grab this value from a dataSet. The calculation figures out how many bars less than the max number of bars a chart will have, by using the afterDataSetFilled to find the number of bars in the current chart. Based on how many fewer bars there are, a value is added for each, to the standard spacing of 50. The value you add for each bar less than the max number of bars depends on your maximum. I determined the best value for this report with a little trial and error. Below is the spacing calculation:
/*Compute spacing -35 = max number of bars;50 = standard unit spacing value;1.428 = the value added to the unit spacing for each bar less than the max number of bars.This number will need to be modified for different max number of bars.Could probably be determined more dynamically.*/
spacing = ((35 - numBars) * 1.428) + 50;

In the example, you can see the same chart with modified spacing and what it looks like by default. This report was designed in BIRT 3.7.2


Michael Williams

eSignLive Evangelism & Community Manager | eSignLive by VASCO
Find me on:


eSignLive Developer Community
Email me:
Google: [email protected]

Sign In or Register to comment.