Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Eclipse Projects » BIRT » Setting bar chart to palette value dynamically
Setting bar chart to palette value dynamically [message #550021] Wed, 28 July 2010 14:53 Go to next message
Eclipse User
Originally posted by: remkus.wideopenwest.com

I'm using BIRT 2.2.1 (constrained to this version by my implementation).

I'm creating a bar chart from a data set that has a column which
contains the value I'm using as my series, and a value which contains an
integer which I'd like to use to change the color of the bar for that
particular bar.

Ex...

Series Value Flag
process1 100 0
process2 98.5 0
process3 98.1 1
process4 99.1 1
process5 99.5 0

So, where the flag is set to 0, I'll use the setting for the first
series palette , when it's 1 I'd like to use the second. (I'm setting
red and green gradients so there's a different pattern for those who
have trouble seeing the difference between red and green)

I'm struggling with a couple of things:

1) I've been trying to follow the examples around scripting the
beforeDrawDataPoints, but if I try to use fill.set(255,0,0), I get the
message 'TypeError: set is not a function. at line xx of chart script:'

2) If I can influence the fill, I'd like to use the series palette
settings so that I can display a gradient, not a solid color.

3) I'm struggling with how to have the script reference the data set,
not a parameter like I've seen in some examples.

I'd very much appreciate the help!

Thanks
Re: Setting bar chart to palette value dynamically [message #550041 is a reply to message #550021] Wed, 28 July 2010 16:08 Go to previous messageGo to next message
Jason Weathersby is currently offline Jason Weathersby
Messages: 9167
Registered: July 2009
Senior Member

Dave,

1 - If you changed the palette to be gradients the script function fill
will not be a ColorDefinitionImpl but a GradientImpl and is most likely
why the set is not working. You can put some code in to test for it:

importPackage(Packages.org.eclipse.birt.chart.model.attribut e.impl);
if( fill.getClass().isAssignableFrom(GradientImpl)){
fill.setStartColor(ColorDefinitionImpl.create( 0, 0, 255 ));
fill.setEndColor(ColorDefinitionImpl.create(255,255,225 ));
}
if( fill.getClass().isAssignableFrom(ColorDefinitionImpl)){
fill.set(..);
}

2 - you can change the palette manually to be gradients. You can also
do this in script. Here is a set of scripts I used on a pie chart to
change the palette colors. I used ColorDefinitionImpl, but you can use
GradientImpl.

piecnt = 0;
startColor = null;
endColor = null;
importPackage( Packages.org.eclipse.birt.chart.model.attribute.impl );

function afterDataSetFilled(series, dataSet, icsc)
{
importPackage( Packages.java.io );
importPackage( Packages.org.eclipse.birt.chart.model.type.impl );

if( series.getClass() == PieSeriesImpl ){
if( series.getSeriesIdentifier() == "mypie" ){
var list = dataSet.getValues();
piecnt = list.length;
}


}
startColor = ColorDefinitionImpl.RED();
endColor = ColorDefinitionImpl.ORANGE();
//startColor = ColorDefinitionImpl.GREY();
//endColor = ColorDefinitionImpl.BLACK();

}
function buildPalette( sliceNumber )
{
var sr = startColor.getRed();
var sg = startColor.getGreen();
var sb = startColor.getBlue();

var er = endColor.getRed();
var eg = endColor.getGreen();
var eb = endColor.getBlue();

var nr = ((er-sr)/piecnt)*sliceNumber + sr;
var ng = ((eg-sg)/piecnt)*sliceNumber + sg;
var nb = ((eb-sb)/piecnt)*sliceNumber + sb;

var nc = ColorDefinitionImpl.create( nr, ng, nb );
return nc;


}

function beforeGeneration( chart, icsc )
{
sd = chart.getSeriesDefinitions( ).get( 0 );
sd.getSeriesPalette( ).getEntries( ).clear( );

for ( i = 1; i <= piecnt; i++ )
{
sd.getSeriesPalette().getEntries().add( buildPalette(i) );
}
}

3 - If the dataset value is not used in the chart getting the value is
problematic. Some ways around this are to load a persistent global
variable HashMap in a hidden table before the chart that uses the same
dataset. Then in script look up the value in the map using the base or
orthogonal value as the key.

Jason


On 7/28/2010 2:53 PM, Dave Remkus wrote:
> I'm using BIRT 2.2.1 (constrained to this version by my implementation).
>
> I'm creating a bar chart from a data set that has a column which
> contains the value I'm using as my series, and a value which contains an
> integer which I'd like to use to change the color of the bar for that
> particular bar.
>
> Ex...
>
> Series Value Flag
> process1 100 0
> process2 98.5 0
> process3 98.1 1
> process4 99.1 1
> process5 99.5 0
>
> So, where the flag is set to 0, I'll use the setting for the first
> series palette , when it's 1 I'd like to use the second. (I'm setting
> red and green gradients so there's a different pattern for those who
> have trouble seeing the difference between red and green)
>
> I'm struggling with a couple of things:
>
> 1) I've been trying to follow the examples around scripting the
> beforeDrawDataPoints, but if I try to use fill.set(255,0,0), I get the
> message 'TypeError: set is not a function. at line xx of chart script:'
>
> 2) If I can influence the fill, I'd like to use the series palette
> settings so that I can display a gradient, not a solid color.
>
> 3) I'm struggling with how to have the script reference the data set,
> not a parameter like I've seen in some examples.
>
> I'd very much appreciate the help!
>
> Thanks
Re: Setting bar chart to palette value dynamically [message #550042 is a reply to message #550041] Wed, 28 July 2010 16:44 Go to previous messageGo to next message
Eclipse User
Originally posted by: remkus.wideopenwest.com

Jason,

I'll have to give that a try ..

In the meanwhile, I had come up with what some may call a clever
solution, while others may call it a kludge ... :)

I had created two additional columns in the bindings. If FLAG is set,
the contents of VALUE gets copied into one column, if not the contents
of VALUE gets copied to the other. Otherwise, the rows would contain a
zero.

e.g.
Series Value Flag Pass Fail
process1 100 0 100 0
process2 98.5 0 98.5 0
process3 98.1 1 0 98.1
process4 99.1 1 0 99.1
process5 99.5 0 99.5 0

Now, I have a straight-forward stacked bar chart.

Thanks!

On 07/28/2010 04:08 PM, Jason Weathersby wrote:
> Dave,
>
> 1 - If you changed the palette to be gradients the script function fill
> will not be a ColorDefinitionImpl but a GradientImpl and is most likely
> why the set is not working. You can put some code in to test for it:
>
> importPackage(Packages.org.eclipse.birt.chart.model.attribut e.impl);
> if( fill.getClass().isAssignableFrom(GradientImpl)){
> fill.setStartColor(ColorDefinitionImpl.create( 0, 0, 255 ));
> fill.setEndColor(ColorDefinitionImpl.create(255,255,225 ));
> }
> if( fill.getClass().isAssignableFrom(ColorDefinitionImpl)){
> fill.set(..);
> }
>
> 2 - you can change the palette manually to be gradients. You can also
> do this in script. Here is a set of scripts I used on a pie chart to
> change the palette colors. I used ColorDefinitionImpl, but you can use
> GradientImpl.
>
> piecnt = 0;
> startColor = null;
> endColor = null;
> importPackage( Packages.org.eclipse.birt.chart.model.attribute.impl );
>
> function afterDataSetFilled(series, dataSet, icsc)
> {
> importPackage( Packages.java.io );
> importPackage( Packages.org.eclipse.birt.chart.model.type.impl );
>
> if( series.getClass() == PieSeriesImpl ){
> if( series.getSeriesIdentifier() == "mypie" ){
> var list = dataSet.getValues();
> piecnt = list.length;
> }
>
>
> }
> startColor = ColorDefinitionImpl.RED();
> endColor = ColorDefinitionImpl.ORANGE();
> //startColor = ColorDefinitionImpl.GREY();
> //endColor = ColorDefinitionImpl.BLACK();
>
> }
> function buildPalette( sliceNumber )
> {
> var sr = startColor.getRed();
> var sg = startColor.getGreen();
> var sb = startColor.getBlue();
>
> var er = endColor.getRed();
> var eg = endColor.getGreen();
> var eb = endColor.getBlue();
>
> var nr = ((er-sr)/piecnt)*sliceNumber + sr;
> var ng = ((eg-sg)/piecnt)*sliceNumber + sg;
> var nb = ((eb-sb)/piecnt)*sliceNumber + sb;
>
> var nc = ColorDefinitionImpl.create( nr, ng, nb );
> return nc;
>
>
> }
>
> function beforeGeneration( chart, icsc )
> {
> sd = chart.getSeriesDefinitions( ).get( 0 );
> sd.getSeriesPalette( ).getEntries( ).clear( );
>
> for ( i = 1; i <= piecnt; i++ )
> {
> sd.getSeriesPalette().getEntries().add( buildPalette(i) );
> }
> }
>
> 3 - If the dataset value is not used in the chart getting the value is
> problematic. Some ways around this are to load a persistent global
> variable HashMap in a hidden table before the chart that uses the same
> dataset. Then in script look up the value in the map using the base or
> orthogonal value as the key.
>
> Jason
>
>
> On 7/28/2010 2:53 PM, Dave Remkus wrote:
>> I'm using BIRT 2.2.1 (constrained to this version by my implementation).
>>
>> I'm creating a bar chart from a data set that has a column which
>> contains the value I'm using as my series, and a value which contains an
>> integer which I'd like to use to change the color of the bar for that
>> particular bar.
>>
>> Ex...
>>
>> Series Value Flag
>> process1 100 0
>> process2 98.5 0
>> process3 98.1 1
>> process4 99.1 1
>> process5 99.5 0
>>
>> So, where the flag is set to 0, I'll use the setting for the first
>> series palette , when it's 1 I'd like to use the second. (I'm setting
>> red and green gradients so there's a different pattern for those who
>> have trouble seeing the difference between red and green)
>>
>> I'm struggling with a couple of things:
>>
>> 1) I've been trying to follow the examples around scripting the
>> beforeDrawDataPoints, but if I try to use fill.set(255,0,0), I get the
>> message 'TypeError: set is not a function. at line xx of chart script:'
>>
>> 2) If I can influence the fill, I'd like to use the series palette
>> settings so that I can display a gradient, not a solid color.
>>
>> 3) I'm struggling with how to have the script reference the data set,
>> not a parameter like I've seen in some examples.
>>
>> I'd very much appreciate the help!
>>
>> Thanks
>
Re: Setting bar chart to palette value dynamically [message #550045 is a reply to message #550042] Wed, 28 July 2010 17:07 Go to previous message
Jason Weathersby is currently offline Jason Weathersby
Messages: 9167
Registered: July 2009
Senior Member

Dave,

I do not think this is a kludge. At least not as bad as my option 3 :>

Jason

On 7/28/2010 4:44 PM, Dave Remkus wrote:
> Jason,
>
> I'll have to give that a try ..
>
> In the meanwhile, I had come up with what some may call a clever
> solution, while others may call it a kludge ... :)
>
> I had created two additional columns in the bindings. If FLAG is set,
> the contents of VALUE gets copied into one column, if not the contents
> of VALUE gets copied to the other. Otherwise, the rows would contain a
> zero.
>
> e.g.
> Series Value Flag Pass Fail
> process1 100 0 100 0
> process2 98.5 0 98.5 0
> process3 98.1 1 0 98.1
> process4 99.1 1 0 99.1
> process5 99.5 0 99.5 0
>
> Now, I have a straight-forward stacked bar chart.
>
> Thanks!
>
> On 07/28/2010 04:08 PM, Jason Weathersby wrote:
>> Dave,
>>
>> 1 - If you changed the palette to be gradients the script function fill
>> will not be a ColorDefinitionImpl but a GradientImpl and is most likely
>> why the set is not working. You can put some code in to test for it:
>>
>> importPackage(Packages.org.eclipse.birt.chart.model.attribut e.impl);
>> if( fill.getClass().isAssignableFrom(GradientImpl)){
>> fill.setStartColor(ColorDefinitionImpl.create( 0, 0, 255 ));
>> fill.setEndColor(ColorDefinitionImpl.create(255,255,225 ));
>> }
>> if( fill.getClass().isAssignableFrom(ColorDefinitionImpl)){
>> fill.set(..);
>> }
>>
>> 2 - you can change the palette manually to be gradients. You can also
>> do this in script. Here is a set of scripts I used on a pie chart to
>> change the palette colors. I used ColorDefinitionImpl, but you can use
>> GradientImpl.
>>
>> piecnt = 0;
>> startColor = null;
>> endColor = null;
>> importPackage( Packages.org.eclipse.birt.chart.model.attribute.impl );
>>
>> function afterDataSetFilled(series, dataSet, icsc)
>> {
>> importPackage( Packages.java.io );
>> importPackage( Packages.org.eclipse.birt.chart.model.type.impl );
>>
>> if( series.getClass() == PieSeriesImpl ){
>> if( series.getSeriesIdentifier() == "mypie" ){
>> var list = dataSet.getValues();
>> piecnt = list.length;
>> }
>>
>>
>> }
>> startColor = ColorDefinitionImpl.RED();
>> endColor = ColorDefinitionImpl.ORANGE();
>> //startColor = ColorDefinitionImpl.GREY();
>> //endColor = ColorDefinitionImpl.BLACK();
>>
>> }
>> function buildPalette( sliceNumber )
>> {
>> var sr = startColor.getRed();
>> var sg = startColor.getGreen();
>> var sb = startColor.getBlue();
>>
>> var er = endColor.getRed();
>> var eg = endColor.getGreen();
>> var eb = endColor.getBlue();
>>
>> var nr = ((er-sr)/piecnt)*sliceNumber + sr;
>> var ng = ((eg-sg)/piecnt)*sliceNumber + sg;
>> var nb = ((eb-sb)/piecnt)*sliceNumber + sb;
>>
>> var nc = ColorDefinitionImpl.create( nr, ng, nb );
>> return nc;
>>
>>
>> }
>>
>> function beforeGeneration( chart, icsc )
>> {
>> sd = chart.getSeriesDefinitions( ).get( 0 );
>> sd.getSeriesPalette( ).getEntries( ).clear( );
>>
>> for ( i = 1; i<= piecnt; i++ )
>> {
>> sd.getSeriesPalette().getEntries().add( buildPalette(i) );
>> }
>> }
>>
>> 3 - If the dataset value is not used in the chart getting the value is
>> problematic. Some ways around this are to load a persistent global
>> variable HashMap in a hidden table before the chart that uses the same
>> dataset. Then in script look up the value in the map using the base or
>> orthogonal value as the key.
>>
>> Jason
>>
>>
>> On 7/28/2010 2:53 PM, Dave Remkus wrote:
>>> I'm using BIRT 2.2.1 (constrained to this version by my implementation).
>>>
>>> I'm creating a bar chart from a data set that has a column which
>>> contains the value I'm using as my series, and a value which contains an
>>> integer which I'd like to use to change the color of the bar for that
>>> particular bar.
>>>
>>> Ex...
>>>
>>> Series Value Flag
>>> process1 100 0
>>> process2 98.5 0
>>> process3 98.1 1
>>> process4 99.1 1
>>> process5 99.5 0
>>>
>>> So, where the flag is set to 0, I'll use the setting for the first
>>> series palette , when it's 1 I'd like to use the second. (I'm setting
>>> red and green gradients so there's a different pattern for those who
>>> have trouble seeing the difference between red and green)
>>>
>>> I'm struggling with a couple of things:
>>>
>>> 1) I've been trying to follow the examples around scripting the
>>> beforeDrawDataPoints, but if I try to use fill.set(255,0,0), I get the
>>> message 'TypeError: set is not a function. at line xx of chart script:'
>>>
>>> 2) If I can influence the fill, I'd like to use the series palette
>>> settings so that I can display a gradient, not a solid color.
>>>
>>> 3) I'm struggling with how to have the script reference the data set,
>>> not a parameter like I've seen in some examples.
>>>
>>> I'd very much appreciate the help!
>>>
>>> Thanks
>>
>
Previous Topic:BIRT viewer and JRun
Next Topic:BIRT - Tomcat: Running problem (please help, probably very easy!)
Goto Forum:
  


Current Time: Wed Aug 20 00:58:33 EDT 2014

Powered by FUDForum. Page generated in 0.01555 seconds