Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Archived » BIRT » Variable bar width in bar graph
Variable bar width in bar graph [message #1015668] Fri, 01 March 2013 15:40 Go to next message
John 555 is currently offline John 555Friend
Messages: 21
Registered: September 2012
Junior Member
Hello,

I have a requirement to have varaible column width in a bar chart. Basically, there are always going to be two columns, one in the positive direction and one in the negative direction. In addition, there will sometimes a third column that can go in either the positive or the negative direction, and will never be longer than the first or second column. The third column should occlude one of the first two columns, depending on whether it is positive or negative.

I am currently doing this by using stacked bars and computed columns to fake occlusion. But, I have just recieved a requirement that the third bar be 2/3 the thickness of the other bars. Is there a non-hacky way of doing this, and if not what is the least hacky way?


John

[Updated on: Fri, 01 March 2013 15:44]

Report message to a moderator

Re: Variable bar width in bar graph [message #1015738 is a reply to message #1015668] Sat, 02 March 2013 01:26 Go to previous messageGo to next message
Michael Williams is currently offline Michael WilliamsFriend
Messages: 1925
Registered: July 2009
Senior Member

The third bar can easily be moved, without using stacked bars. If you had bars for A, B, and C with A being positive, B negative and C the moving bar, you could move the 3rd to the appropriate location with something like:

function beforeDrawSeries( series, isr, icsc )

{
if( series.getSeriesIdentifier() == "Series 1" ){
var dpharray = isr.getSeriesRenderingHints().getDataPoints();
for( j=0;j<dpharray.length;j++){
if(dpharray[j].getBaseDisplayValue() == "A"){
newNegX = dpharray[j].getLocation().getX();
}
else if(dpharray[j].getBaseDisplayValue() == "B"){
newPosX = dpharray[j].getLocation().getX();
}
if(dpharray[j].getBaseDisplayValue() == "C"){
if(dpharray[j].getOrthogonalValue() < 0){
dpharray[j].getLocation().setX(newNegX);
}
else{
dpharray[j].getLocation().setX(newPosX);
}
}
}

}
}

The thickness of the 3rd bar is the tough one. The width is set with the unit spacing which is set for the entire chart. Setting an image as the background to make it appear like a thinner bar might be an option. If I think of another way, I'll let you know.


Michael

Developer Evangelist, Silanis

[Updated on: Sat, 02 March 2013 01:28]

Report message to a moderator

Re: Variable bar width in bar graph [message #1015739 is a reply to message #1015668] Sat, 02 March 2013 01:44 Go to previous messageGo to next message
Michael Williams is currently offline Michael WilliamsFriend
Messages: 1925
Registered: July 2009
Senior Member

With an image for the third bar, you can make it look like this:

index.php/fa/13642/0/
  • Attachment: SkinnyBar.PNG
    (Size: 5.94KB, Downloaded 1841 times)


Michael

Developer Evangelist, Silanis
Re: Variable bar width in bar graph [message #1015746 is a reply to message #1015739] Sat, 02 March 2013 03:25 Go to previous messageGo to next message
John 555 is currently offline John 555Friend
Messages: 21
Registered: September 2012
Junior Member
Hello Michael,

I did try the image solution for modifying the bar width, but it didn't work for me because in my report the number of x-axis groups is determined at run time. Because images are repeated rather than stretched when they don't match up to a bar size, creating the illusion of a thinner bar depends on knowing the width of the actual bar beforehand. I'm not sure if there is a way around this.

John

Re: Variable bar width in bar graph [message #1016105 is a reply to message #1015746] Tue, 05 March 2013 05:35 Go to previous messageGo to next message
Michael Williams is currently offline Michael WilliamsFriend
Messages: 1925
Registered: July 2009
Senior Member

Based on your original post, it seemed that you'd only ever have 3 bars. I guess I missed something in the post. The only thing I could think of for multiple sizes needed would be to have several image options that you could replace the original bar image with, depending on the number of groupings.

Michael

Developer Evangelist, Silanis
Re: Variable bar width in bar graph [message #1016286 is a reply to message #1016105] Tue, 05 March 2013 20:15 Go to previous messageGo to next message
John 555 is currently offline John 555Friend
Messages: 21
Registered: September 2012
Junior Member
Hello Michael,

Sorry, I said columns when I meant series. There will always be three series. One of the series will always have a negative bar, one will always have a positive bar, and one can be either positive or negative. There may be more than one entry in the chart however, so the total number of columns does vary.

I have attached an example of my situation. Currently, I am using stacked bars. What I want is to make the red bar thinner, so that whichever bar ends up behind it can be seen. The number of rows in the data set will vary.

John
Re: Variable bar width in bar graph [message #1016315 is a reply to message #1016286] Wed, 06 March 2013 01:30 Go to previous messageGo to next message
Michael Williams is currently offline Michael WilliamsFriend
Messages: 1925
Registered: July 2009
Senior Member

It looks like changing the unit spacing between series is possible, so try something like this:

var oldSpacing = 50;
function beforeDrawSeries( series, isr, icsc )

{
oldSpacing = icsc.getChartInstance().getUnitSpacing();
if( series.getSeriesIdentifier() == "series 3" ){
icsc.getChartInstance().setUnitSpacing(70);
}
}

function afterDrawSeries( series, isr, icsc )
{
icsc.getChartInstance().setUnitSpacing(oldSpacing);
}


Michael

Developer Evangelist, Silanis
Re: Variable bar width in bar graph [message #1016536 is a reply to message #1016315] Wed, 06 March 2013 19:49 Go to previous messageGo to next message
John 555 is currently offline John 555Friend
Messages: 21
Registered: September 2012
Junior Member
Michael,

I don't think that changing the series spacing alone can resolve this issue. I have attached an ms-painted demo of what I am trying to create. I need to both change the width of a bar, and cause one bar to occlude one another.

John

[Updated on: Wed, 06 March 2013 19:50]

Report message to a moderator

Re: Variable bar width in bar graph [message #1016538 is a reply to message #1016536] Wed, 06 March 2013 19:57 Go to previous messageGo to next message
Michael Williams is currently offline Michael WilliamsFriend
Messages: 1925
Registered: July 2009
Senior Member

Using that idea along with part of the idea above for moving the bar might work. If you create a sample report showing how your report is set up, using the sample database, I can do some testing on it.

Michael

Developer Evangelist, Silanis
Re: Variable bar width in bar graph [message #1016548 is a reply to message #1016538] Wed, 06 March 2013 20:58 Go to previous messageGo to next message
John 555 is currently offline John 555Friend
Messages: 21
Registered: September 2012
Junior Member
The report design I attached a few posts ago demonstrates the layout that I am using. It is using a very simple scripted data set.
Re: Variable bar width in bar graph [message #1016550 is a reply to message #1016548] Wed, 06 March 2013 21:00 Go to previous messageGo to next message
Michael Williams is currently offline Michael WilliamsFriend
Messages: 1925
Registered: July 2009
Senior Member

Oops. Sorry. My mistake. Smile

Michael

Developer Evangelist, Silanis
Re: Variable bar width in bar graph [message #1016575 is a reply to message #1015668] Thu, 07 March 2013 00:11 Go to previous messageGo to next message
Michael Williams is currently offline Michael WilliamsFriend
Messages: 1925
Registered: July 2009
Senior Member

Take a look at this modification of your report. The formula to figure the offset might need to be tweaked a little, if you add a title, specifically the -10 portion. This accounts for the dead space at the top of the chart which would be increased with a title. This was just a first shot at a formula to figure the offset needed, but it should be a start. I'll let you know if I find a better way.

I unstacked the second series and then moved it down half the offset and the stacked bars up half the offset, to meet in the middle. I added a parameter to the report to determine the number of rows in the dataSet, so that different variations could be tested. This appears to work pretty well for any value.

Let me know if you have questions.


Michael

Developer Evangelist, Silanis
Re: Variable bar width in bar graph [message #1017031 is a reply to message #1016575] Fri, 08 March 2013 17:13 Go to previous messageGo to next message
John 555 is currently offline John 555Friend
Messages: 21
Registered: September 2012
Junior Member
Hello Michael,

This works nicely. I do notice that if you hard code the variable series to not be stacked, it causes all of the series bars to be smaller than normal, whereas scripting the bar to unstack itself doesn't have this issue. I should be able to figure it out at this point. If I have any issues, I will post about them.

Thanks,
John

Re: Variable bar width in bar graph [message #1017080 is a reply to message #1017031] Fri, 08 March 2013 21:28 Go to previous message
Michael Williams is currently offline Michael WilliamsFriend
Messages: 1925
Registered: July 2009
Senior Member

You could probably just adjust the unit spacing in the chart, the way it is set up now and it wouldn't be an issue. Let me know.

Michael

Developer Evangelist, Silanis
Previous Topic:How to do Client Printing and delete xml source file
Next Topic:3 data columns, one cell and IF statements?
Goto Forum:
  


Current Time: Sat Oct 12 14:15:58 GMT 2024

Powered by FUDForum. Page generated in 0.06567 seconds
.:: Contact :: Home ::.

Powered by: FUDforum 3.0.2.
Copyright ©2001-2010 FUDforum Bulletin Board Software

Back to the top