| Variable bar width in bar graph [message #1015668] |
Fri, 01 March 2013 10:40  |
John 555 Messages: 20 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 10:44] Report message to a moderator
|
|
|
| Re: Variable bar width in bar graph [message #1015738 is a reply to message #1015668] |
Fri, 01 March 2013 20:26   |
|
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.
Regards,
Michael Williams
BIRT Exchange
Michael's BIRT Blog
[Updated on: Fri, 01 March 2013 20:28] Report message to a moderator
|
|
|
|
|
|
|
| Re: Variable bar width in bar graph [message #1016315 is a reply to message #1016286] |
Tue, 05 March 2013 20:30   |
|
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);
}
Regards,
Michael Williams
BIRT Exchange
Michael's BIRT Blog
|
|
|
|
|
|
|
| Re: Variable bar width in bar graph [message #1016575 is a reply to message #1015668] |
Wed, 06 March 2013 19:11   |
|
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.
Regards,
Michael Williams
BIRT Exchange
Michael's BIRT Blog
|
|
|
|
|
Powered by
FUDForum. Page generated in 0.02085 seconds