Home
Analytics
To set the bar width on Bar Chart
jain
Hi, I have created a bar chart report, I want to set the width of the bar in inches dynamically based on the number of bars. So I have set the bar width in beforeGeneration method using chart.setUnitSpacing(), but the bar width is not exactly matching, have following questions: 1. In which unit do I need to set the unit spacing (either in points/pixels/inches)?
2. How to set the width of the bar in inches?
Find more posts tagged with
Comments
kclark
When using setWidth() it's expecting an integer for pixels. If you want to adjust the width of the bars you could use a some script like this.<br />
<br />
<pre class='_prettyXprint _lang-auto _linenums:0'>function beforeGeneration( chart, context )
{
chart.setUnitSpacing(50);
}
var oldSpacing;
function beforeDrawSeries( series, seriesRenderer, context )
{
oldSpacing = context.getChartInstance().getUnitSpacing();
if( series.getSeriesIdentifier() == "series one" ){
context.getChartInstance().setUnitSpacing(70);
}
}
function afterDrawSeries( series, seriesRenderer, context )
{
context.getChartInstance().setUnitSpacing(oldSpacing);
}</pre>
<br />
<br />
This part chart.setUnitSpacing(50); is what you would change to increase or decrease the size of the bars. 0 being the bars touching and the higher you go the smaller they get.
jain
Thanks Kclark for your response, actually I need to set the bar width based on number of bars in inches. I have set the bar width using chart.setUnitSpacing() in beforeGeneration function, but the width is not coming properly.
For example,
if number of bars >= 1 and <= 3, then need to set the bar width to be 0.8 inches. Is there a way where I can set the width exactly?
jain
Hi Kclark, I was trying to set the bar width using chart.setUnitspacing(57) in beforeGeneration function, but I couldnt able to set 0.8 inch exactly. could you please let me know how could I set the bar width 0.8 inch exactly? also please let me know setUnitSpacing method is considering which unit(pixel/points)?
kclark
jain, there isn't a way to set the bar width by inches. You can <a class='bbc_url' href='
http://www.eclipse.org/birt/phoenix/reportabug.php'>file
an enhancement request here</a> though.
jain
Thanks Kclark for the information, I will file an enhancement request.