Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Eclipse Projects » BIRT » Controlling the width of a bar on a bar chart
Controlling the width of a bar on a bar chart [message #997492] Mon, 07 January 2013 14:08 Go to next message
Mike Wulkan is currently offline Mike Wulkan
Messages: 141
Registered: July 2009
Senior Member
I was wondering if there was a way to specify the width of the bars on a bar chart?
The scenario is:
I have two bar charts that are to be displayed one above the other. The look & feel of the charts are to be identical except for the actual data displayed.

The problem is that the number of category (X) values may differ. Because of this, even though the charts are the same size, the width of the bars differ because one chart has less entries than the other chart.

This has the undesirable effect of making the chart with fewer categories look more important (heavier) than the other chart because the width of the bars are larger even though both charts should be perceived equally.

Thoughts?
Re: Controlling the width of a bar on a bar chart [message #997506 is a reply to message #997492] Mon, 07 January 2013 16:05 Go to previous messageGo to next message
Michael Williams is currently offline Michael Williams
Messages: 1547
Registered: July 2009
Senior Member

This may not work for you, since it sounds like you're wanting to keep the chart size exactly the same, but it's worth a look. The link is to a devShare post on BIRT Exchange that shows how to change the size of the chart based on the number of bars, to keep the consistent look.

BIRT Exchange DevShare - Resize Chart Based on Data


Michael

Add interactivity, scheduling, sharing, live Excel export, and JS integration to your BIRT app with the new, free BIRT server, BIRT iHub F-Type.
Re: Controlling the width of a bar on a bar chart [message #998247 is a reply to message #997506] Wed, 09 January 2013 11:43 Go to previous messageGo to next message
Mike Wulkan is currently offline Mike Wulkan
Messages: 141
Registered: July 2009
Senior Member
Thanks for this, although my original desire was to keep the chart the same size, I might settle for this approach if there is no reasonable way to achieve what I want.
Re: Controlling the width of a bar on a bar chart [message #998257 is a reply to message #998247] Wed, 09 January 2013 12:14 Go to previous messageGo to next message
Michael Williams is currently offline Michael Williams
Messages: 1547
Registered: July 2009
Senior Member

I'll take a closer look at your issue, this afternoon. There is a setting for unit spacing that can be set, but there may be an issue of when it can be set. What's your BIRT version? I'll be looking at 3.7.2, unless I hear a different version from you before I get to it.

Michael

Add interactivity, scheduling, sharing, live Excel export, and JS integration to your BIRT app with the new, free BIRT server, BIRT iHub F-Type.
Re: Controlling the width of a bar on a bar chart [message #998486 is a reply to message #997492] Wed, 09 January 2013 23:54 Go to previous messageGo to next message
Michael Williams is currently offline Michael Williams
Messages: 1547
Registered: July 2009
Senior Member

Take a look at this report. It calculates a spacing based off the number of bars. The number 37, used in the script, is the max number of bars in the chart, when USA is selected. This is the base number for the calculation. Let me know if you have questions.



Michael

Add interactivity, scheduling, sharing, live Excel export, and JS integration to your BIRT app with the new, free BIRT server, BIRT iHub F-Type.
Re: Controlling the width of a bar on a bar chart [message #998698 is a reply to message #998486] Thu, 10 January 2013 09:30 Go to previous messageGo to next message
Mike Wulkan is currently offline Mike Wulkan
Messages: 141
Registered: July 2009
Senior Member
I tried the technique from the example report you provided. It has promise but the values used in the computation do not make the bar sizes in the two charts equal.

The script I used is as follows
function afterDataSetFilled( series, dataSet, icsc )
{
if(series.getSeriesIdentifier() == "Series 1"){
	numBars1 = dataSet.getValues().length;
}
}

function beforeGeneration( chart, icsc )
{

spacing = ((8 - numBars1) * 1.32) + 50;

chart.setUnitSpacing(spacing);
}


, where in my case 8 is the maximum number of bars and is equal to the number of bars in the first chart (I used the same script for both charts).
The second chart has only 5 bars. I see that the script indeed increases the unit spacing for the second chart, but not enough to cause the bar size to be the same as the first chart.

The charts render as follows:
https://dl.dropbox.com/u/46622089/bar1.png

Where do the values 1.32 and 50 come from and how might I tweak them such that I can achieve my desired effect?

Thanks,
Mike
Re: Controlling the width of a bar on a bar chart [message #998704 is a reply to message #998698] Thu, 10 January 2013 09:36 Go to previous messageGo to next message
Mike Wulkan is currently offline Mike Wulkan
Messages: 141
Registered: July 2009
Senior Member
Experimenting... for this particular number of bars changing 1.32 to 3 appears to be around the right value but I am not convinced that this would extrapolate to different numbers of bars.
Re: Controlling the width of a bar on a bar chart [message #998728 is a reply to message #998704] Thu, 10 January 2013 10:12 Go to previous messageGo to next message
Mike Wulkan is currently offline Mike Wulkan
Messages: 141
Registered: July 2009
Senior Member
Hmmm... from the chapter on not really knowing what one wants....
I tried the code that resized the chart based on the number of bars rather than resizing the bars and I liked the results better. In this example the script reads:

totalBars = 0;

function afterDataSetFilled( series, dataSet, icsc )
{
totalBars = dataSet.getValues().length;
}

function beforeGeneration( chart, icsc )
{
if (totalBars < 45){
	chart.getBlock().getBounds().setHeight(100 + (totalBars*15));
}
else{
chart.getBlock().getBounds().setHeight(765);
}
}


However I found that I needed to change the 15 to 13 to really make it work along with changing the setWidth to setHeight since I rotated the axis. Again I am curious as to what the value 15 is based on (font size etc...) so I can be sure that I am setting it correctly?
Re: Controlling the width of a bar on a bar chart [message #998766 is a reply to message #998728] Thu, 10 January 2013 11:54 Go to previous message
Michael Williams is currently offline Michael Williams
Messages: 1547
Registered: July 2009
Senior Member

Sorry, I did a poor job of explaining the spacing deal. The 1.32 was based on the number of bars I could have had. 50 is the standard setting for the unit spacing in your chart, so I used that as a base and then essentially found an approximate value (1.32) to make the charts appear to be very close to the same. The unit spacing range is from 0-100. Unfortunately, the bar width is controlled by unit spacing and not a set bar width, so, this will be something you have to deal with, probably.

With the other report, it was the same deal. I just calculated an approximate number to work. You were more particular with it being exact, I'm sure. I was just creating an example. Smile


Michael

Add interactivity, scheduling, sharing, live Excel export, and JS integration to your BIRT app with the new, free BIRT server, BIRT iHub F-Type.
Previous Topic:Dynamic data and tables
Next Topic:How to call BIRT Report in JSP Page
Goto Forum:
  


Current Time: Wed Jul 30 07:13:49 EDT 2014

Powered by FUDForum. Page generated in 0.02265 seconds