Variable bar width in bar graph [message #1015668] |
Fri, 01 March 2013 15:40 |
John 555 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 |
|
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 #1016105 is a reply to message #1015746] |
Tue, 05 March 2013 05:35 |
|
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 #1016315 is a reply to message #1016286] |
Wed, 06 March 2013 01: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);
}
Michael
Developer Evangelist, Silanis
|
|
|
|
Re: Variable bar width in bar graph [message #1016538 is a reply to message #1016536] |
Wed, 06 March 2013 19:57 |
|
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 #1016575 is a reply to message #1015668] |
Thu, 07 March 2013 00: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.
Michael
Developer Evangelist, Silanis
|
|
|
|
|
Powered by
FUDForum. Page generated in 0.04367 seconds