Skip to main content



      Home
Home » Archived » BIRT » Charts: What are scripts for?
Charts: What are scripts for? [message #85261] Fri, 28 October 2005 09:41 Go to next message
Eclipse UserFriend
Hello,

Under the chart builder one can choose Scripts.
What are these scripts for, what I can do with the scripts?

Thanks for help!
Re: Charts: What are scripts for? [message #85351 is a reply to message #85261] Fri, 28 October 2005 12:33 Go to previous messageGo to next message
Eclipse UserFriend
Hi,

The scripts allow you to customize the chart while it is being generated and
rendered. For instance you might want to change the color of some Y serie
for outstanding values, you can achieve that result with a script.

You can check the script specification here:
http://www.eclipse.org/birt/wiki/index.php?n=BPS.BPS18 (note that the spec
covers both 1.0.1 and 2.0 script features).

There are also some explanations in the FAQ file shipped in the Chart
distribution.

Thanks,

David

Note that this specification covers 1.0.1 and 2.0. Also there should be some
examples and documentation somewhere
"Mr. Burns" <Mr._Burns@web.de> wrote in message
news:djt9qa$5ek$1@news.eclipse.org...
> Hello,
>
> Under the chart builder one can choose Scripts.
> What are these scripts for, what I can do with the scripts?
>
> Thanks for help!
>
Re: Charts: What are scripts for? [message #86556 is a reply to message #85351] Wed, 02 November 2005 08:25 Go to previous messageGo to next message
Eclipse UserFriend
Hello David,

thanks for reply,

You wrote:

> Note that this specification covers 1.0.1 and 2.0. Also there should be
> some examples and documentation somewhere

I tried now several hours to find an example how to use the Scripts section
under chart builder.

I did not find anything. All scripting information I found are for the
reporting, not for the charting.
So what I can do with this Scripts section?
Can I enter JavaScript code there? How to access the this script out of e.g.
beforeDrawBlock()?

How to change color of a bar depending on the psotive/negative value as you
mentioned?

Thanks for additional help, (really hard for a newbee to get useful
information)
Re: Charts: What are scripts for? [message #86894 is a reply to message #86556] Thu, 03 November 2005 08:19 Go to previous messageGo to next message
Eclipse UserFriend
You enter your script directly in the text box, including the function body:
"function beforeDrawElement(dPh, fill){...}"

Here is an example from the Chart FAQ doc
www.eclipse.org/birt/faq/Charts_FAQ.doc
: www.eclipse.org/birt/faq/Charts_FAQ.doc


Chart cm = .;

cm.setScript("function beforeDrawDataPoint(dataPointHints, label) { val =
dataPointHints.getOrthogonalValue(); clr = label.getCaption().getColor(); if
(val < 0) clr.set(255, 0, 0); else clr.set(0, 0, 255); }");



This JavaScript method would attempt to set the text color of a rendered
data point to red if the orthogonal value being plotted is negative and to
blue if the value is zero or positive.



--

And another one to change the colors of the bars:


function beforeDrawElement(dataPointHints, fill)
{

if ( dataPointHints.getOrthogonalValue()<0)
fill.set(255, 0,0);

else

fill.set(0,255,0);

}

Hope that helps, I will see that the documentation is improved on that
subject for the next release :)



Thanks,



David



"Mr. Burns" <Mr._Burns@web.de> wrote in message
news:dkaeoi$qjv$1@news.eclipse.org...
> Hello David,
>
> thanks for reply,
>
> You wrote:
>
>> Note that this specification covers 1.0.1 and 2.0. Also there should be
>> some examples and documentation somewhere
>
> I tried now several hours to find an example how to use the Scripts
> section under chart builder.
>
> I did not find anything. All scripting information I found are for the
> reporting, not for the charting.
> So what I can do with this Scripts section?
> Can I enter JavaScript code there? How to access the this script out of
> e.g. beforeDrawBlock()?
>
> How to change color of a bar depending on the psotive/negative value as
> you mentioned?
>
> Thanks for additional help, (really hard for a newbee to get useful
> information)
>
Re: Charts: What are scripts for? [message #86909 is a reply to message #86894] Thu, 03 November 2005 09:02 Go to previous messageGo to next message
Eclipse UserFriend
Hello David,

thanks for your reply, but what you wrote I already found, thanks anyway.
Exactly the

Chart cm = ...;

also found in the documentation, is the problem.
What I have to enter for the ...?

I am NOT within a JAVA application where I want to create a report.
I am within the report builder and directly within the Script area.

So if I write Chart cm = ... there, it obviously makes no sense, I have to
get the handle for the chart I am within and not create a new one.

In the document you mentioned Chart_FAQ no hint I found how to use the
Script area of the expression builder. Only how to manupulate a chart out of
an JAVA application.

Any further idea?
Re: Charts: What are scripts for? [message #86924 is a reply to message #86894] Thu, 03 November 2005 09:35 Go to previous messageGo to next message
Eclipse UserFriend
If I enter following code in the Script area, I get a partial success:

function beforeDrawDataPoint(dataPointHints, label)
{
val = dataPointHints.getOrthogonalValue();
clr = label.getCaption().getColor();
if (val < 100)
{
clr.set(255, 0, 0);
}
else
{
importPackage(Packages.javax.swing);
frame = new JFrame(val);
frame.setBounds(310, 220, 300, 20);
frame.show();
clr.set(0, 0, 255);
}
};

I can see the small frame popping up, so the code is executes, but I don't
see any color changing.
What color exactly should change? What is clr (label.getCaption().getColor)
is this the orthogonal value above each bar?

So the code is executed but no color changes on the chart.

Need help again!
Re: Charts: What are scripts for? [message #86939 is a reply to message #86924] Thu, 03 November 2005 09:42 Go to previous messageGo to next message
Eclipse UserFriend
Originally posted by: sangria.gmx.net

In a bar chart this code will change the number that is printed above
each bar. It will change the font color from black to red for all values
that are smaller than 100.
Does this help?

Cheers, michael

Mr. Burns schrieb:
> If I enter following code in the Script area, I get a partial success:
>
> function beforeDrawDataPoint(dataPointHints, label)
> {
> val = dataPointHints.getOrthogonalValue();
> clr = label.getCaption().getColor();
> if (val < 100)
> {
> clr.set(255, 0, 0);
> }
> else
> {
> importPackage(Packages.javax.swing);
> frame = new JFrame(val);
> frame.setBounds(310, 220, 300, 20);
> frame.show();
> clr.set(0, 0, 255);
> }
> };
>
> I can see the small frame popping up, so the code is executes, but I don't
> see any color changing.
> What color exactly should change? What is clr (label.getCaption().getColor)
> is this the orthogonal value above each bar?
>
> So the code is executed but no color changes on the chart.
>
> Need help again!
>
>
Re: Charts: What are scripts for? [message #86954 is a reply to message #86909] Thu, 03 November 2005 09:53 Go to previous messageGo to next message
Eclipse UserFriend
Sorry this example was for API users. You can simply ignore the Chart
cm=...;
The script area should include only the JavaScript Code between quotes in my
email :

function beforeDrawDataPoint(dataPointHints, label) { val =
dataPointHints.getOrthogonalValue(); clr = label.getCaption().getColor(); if
(val < 0) clr.set(255, 0, 0); else clr.set(0, 0, 255); }

The label color will change for each datapoint.

Thanks,

David


"Mr. Burns" <Mr._Burns@web.de> wrote in message
news:dkd59t$8q8$1@news.eclipse.org...
> Hello David,
>
> thanks for your reply, but what you wrote I already found, thanks anyway.
> Exactly the
>
> Chart cm = ...;
>
> also found in the documentation, is the problem.
> What I have to enter for the ...?
>
> I am NOT within a JAVA application where I want to create a report.
> I am within the report builder and directly within the Script area.
>
> So if I write Chart cm = ... there, it obviously makes no sense, I have to
> get the handle for the chart I am within and not create a new one.
>
> In the document you mentioned Chart_FAQ no hint I found how to use the
> Script area of the expression builder. Only how to manupulate a chart out
> of an JAVA application.
>
> Any further idea?
>
>
>
Re: Charts: What are scripts for? [message #86986 is a reply to message #86939] Thu, 03 November 2005 10:09 Go to previous messageGo to next message
Eclipse UserFriend
thanks,

Ok, the number above each bar should change the font color. But it doesn't!

If I look on the reports viewer log I get an error message:

03.11.2005 16:04:13 org.eclipse.birt.chart.log.impl.JavaUtilLoggerImpl log
SCHWERWIEGEND: Exception
org.eclipse.birt.chart.exception.ChartException: $NO-RB$ TypeError:
getCaption is not a function. (<cmd>#7)

So what to do now?
Re: Charts: What are scripts for? [message #87001 is a reply to message #86954] Thu, 03 November 2005 10:10 Go to previous messageGo to next message
Eclipse UserFriend
thanks,

Ok, the number above each bar should change the font color. But it doesn't!

If I look on the reports viewer log I get an error message:

03.11.2005 16:04:13 org.eclipse.birt.chart.log.impl.JavaUtilLoggerImpl log
SCHWERWIEGEND: Exception
org.eclipse.birt.chart.exception.ChartException: $NO-RB$ TypeError:
getCaption is not a function. (<cmd>#7)

So what to do now?
Re: Charts: What are scripts for? [message #87060 is a reply to message #85261] Thu, 03 November 2005 10:42 Go to previous messageGo to next message
Eclipse UserFriend
If I use following code in the script:

function beforeDrawDataPoint(dataPointHints, label)
{
cpt = label.getCaption();
clr = cpt.getColor();

clr.set(255,0,0);
};

it should show all labels in red, am I right?

Now I don't get any error messages anymore within the viewer log, but still
no color changing.
All orthogonal values keep shown in black.

So my question, is beforeDrawDataPoint the right event to do anything on the
colors?
Is there something missing after clr.set(...) something like
chart.update()?

Any help is highly appreciated!
Re: Charts: What are scripts for? [message #87090 is a reply to message #87001] Thu, 03 November 2005 10:43 Go to previous messageGo to next message
Eclipse UserFriend
Originally posted by: sangria.gmx.net

The example below works for me in the BIRT RCP Designer. Pherhaps you
want to try it.

-Create a new report
-Create a new datasource (based on Classic model inc. Sample Database)
-Create a new dataset with the following query:
SELECT customernumber, sum(amount) as amount from payments
where customernumber < 130 group by customernumber
-Create a new bar chart
-Set the x-series to customernumber and the y-series to amount
-Have a look at the chart
-Add the following script (Press update after you added the script):

function beforeDrawDataPoint(dataPointHints, label)
{
value = dataPointHints.getOrthogonalValue();
color = label.getCaption().getColor();
if (value > 180000)
color.set(255, 0, 0);
else
color.set(0, 0, 255);
}

-Look at the chart again. You should have two red labels now.

michael


Mr. Burns schrieb:
> thanks,
>
> Ok, the number above each bar should change the font color. But it doesn't!
>
> If I look on the reports viewer log I get an error message:
>
> 03.11.2005 16:04:13 org.eclipse.birt.chart.log.impl.JavaUtilLoggerImpl log
> SCHWERWIEGEND: Exception
> org.eclipse.birt.chart.exception.ChartException: $NO-RB$ TypeError:
> getCaption is not a function. (<cmd>#7)
>
> So what to do now?
>
>
Re: Charts: What are scripts for? [message #87105 is a reply to message #87090] Thu, 03 November 2005 10:50 Go to previous messageGo to next message
Eclipse UserFriend
I tried your code but no success I get an error message in the viewer log
again:

GRAVE: Exception
org.eclipse.birt.chart.exception.ChartException: $NO-RB$ TypeError:
getCaption is not a function. (<cmd>#7)

Only if I modify the code like:

function beforeDrawDataPoint(dataPointHints, label)
{
value = dataPointHints.getOrthogonalValue();

caption = label.getCaption(); // <-- Added here
color = caption.getColor(); // <-- modified here

if (value > 180000)
color.set(255, 0, 0);
else
color.set(0, 0, 255);
}

then I don't get the error message within the viewer log, but still the
labels are black, no color changing at all :-(
Re: Charts: What are scripts for? [message #87134 is a reply to message #87090] Thu, 03 November 2005 11:00 Go to previous messageGo to next message
Eclipse UserFriend
Hello,

now I got it working also with your code, no error message anymore within
the viewers log file.
But I have really no idea why! I completely deleted the code from the script
area and copied your code in.

BUT:

Color keeps black! aaaarrrrggghhhh!

Any further ideas?

Can I try to change color on a different label? How about the labels diagram
title and/or axis titles to change color? How do I access them?
So I have more that I can try maybe this helsp me to find out more!?

Thanks!
Re: Charts: What are scripts for? [message #87163 is a reply to message #87134] Thu, 03 November 2005 11:23 Go to previous messageGo to next message
Eclipse UserFriend
What version of BIRT are you using? What platform are you running it on?

Thanks,

David

"Mr. Burns" <Mr._Burns@web.de> wrote in message
news:dkdc5n$jpv$1@news.eclipse.org...
> Hello,
>
> now I got it working also with your code, no error message anymore within
> the viewers log file.
> But I have really no idea why! I completely deleted the code from the
> script area and copied your code in.
>
> BUT:
>
> Color keeps black! aaaarrrrggghhhh!
>
> Any further ideas?
>
> Can I try to change color on a different label? How about the labels
> diagram title and/or axis titles to change color? How do I access them?
> So I have more that I can try maybe this helsp me to find out more!?
>
> Thanks!
>
>
Re: Charts: What are scripts for? [message #87178 is a reply to message #87060] Thu, 03 November 2005 11:25 Go to previous messageGo to next message
Eclipse UserFriend
no, the code should work, there is no update to do, since it's being called
during the rendering. Can you attach a report with the chart you're having
problem with? I will take a look.

Thanks,

David

"Mr. Burns" <Mr._Burns@web.de> wrote in message
news:dkdb4u$i12$1@news.eclipse.org...
> If I use following code in the script:
>
> function beforeDrawDataPoint(dataPointHints, label)
> {
> cpt = label.getCaption();
> clr = cpt.getColor();
>
> clr.set(255,0,0);
> };
>
> it should show all labels in red, am I right?
>
> Now I don't get any error messages anymore within the viewer log, but
> still no color changing.
> All orthogonal values keep shown in black.
>
> So my question, is beforeDrawDataPoint the right event to do anything on
> the colors?
> Is there something missing after clr.set(...) something like
> chart.update()?
>
> Any help is highly appreciated!
>
>
Re: Charts: What are scripts for? [message #87386 is a reply to message #87163] Fri, 04 November 2005 03:49 Go to previous messageGo to next message
Eclipse UserFriend
Hello,

I am using BIRT 1.0.1 under Eclipse 3.1.0 Build id: I20050627-1435
Re: Charts: What are scripts for? [message #87400 is a reply to message #87178] Fri, 04 November 2005 03:54 Go to previous messageGo to next message
Eclipse UserFriend
Hello David,

I attached the rptdesign file and also an file containing the SL statements
to create the itemsales table usen in my chart

Thanks for further support!




Re: Charts: What are scripts for? [message #87461 is a reply to message #87163] Fri, 04 November 2005 05:57 Go to previous messageGo to next message
Eclipse UserFriend
Hello,

I found out, that following function works:

function beforeDrawElement(dataPointHints, el)
{
el.set(255, 0, 0); // <-- Works, all bars and legend elements appear in
red
}

function beforeDrawAxisTitle(Axis, Label)
{
caption = Label.getCaption();
color = caption.getColor();
color.set(255, 0, 0); // <-- does not work
}

function beforeDrawDataPoint(Axis, Label)
{
caption = Label.getCaption();
color = caption.getColor();
color.set(255, 0, 0); // <-- does not work
}

So it seems that changing color of any text or font element does not work,
does this give anyone a hint?

Thanks or further help!
Re: Charts: What are scripts for? [message #88239 is a reply to message #87178] Mon, 07 November 2005 10:39 Go to previous messageGo to next message
Eclipse UserFriend
Hello David,

did you find time to check my report?
Re: Charts: What are scripts for? [message #88485 is a reply to message #88239] Mon, 07 November 2005 14:47 Go to previous messageGo to next message
Eclipse UserFriend
Yes, sorry I didn't realize my answer got stuck in my outbox (I attached a
large screenshot too big for the newsgroup apparently).

Your report works fine for me, all the labels are changed to red. Maybe
there is something wrong with your BIRT installation?

Thanks,

David

"Mr. Burns" <Mr._Burns@web.de> wrote in message
news:dknsfd$8me$1@news.eclipse.org...
> Hello David,
>
> did you find time to check my report?
>
>
Finally I found out what the problem was! Yeah!!! [message #89612 is a reply to message #88485] Thu, 10 November 2005 06:29 Go to previous message
Eclipse UserFriend
Hello David,

It took me two days to find out why the function:

function beforeDrawDataPoint(dataPointHints, label)
{
label.getCaption().getColor().set(255, 0, 0);
}

in the Scripts area does not work. The color of the label above each bar
kept black instead of red, what I programmed.

I found out that there is a difference on HOW you create your report.

If you go to File->New->Report

Then you have the options:

1. Click Next (e.g. to choose a template report)
2. Click Finish to create a blank report

If you choose the 1st option (Next) and choose a template (MUST INCLUDE A
CHART!!!) then the script works, so the color of the label above the bars
turns to red.

If you use the 2nd option (Finish) and drag a chart from the Palette to the
blank report, then the script is not executed, even if its was added under
the Scripts area!!!

So now the reason:

If you look under the XML Source of the report, some tags about the label
are missing, it is within the section:

<Axes>
<AssociatedAxes>
<SeriesDefinitions>
<Series xsi:type="type:BarSeries">
<Label>
<Caption>
<Value>&lt;undefined></Value> <!-- Here are <Font>...</Font>
and <Color>...</Color> missing!!! Not missing only if using a template chart
</Caption>

To solve this problem one can do following:

I you go into the report builder Attributes->Y-Series->Lables and choose a
color (e.g. blue) of the font (by clicking the ... button) then the
<Font>...</Font> and <Color>...</Color> are added to the XML source, and
then the Script function works!

So hope that helps other who will have this or similar problem in the
future!

Best regards,

Mr. Burns
Previous Topic:Build BIRT project
Next Topic:After update to 2.0 still problems with color
Goto Forum:
  


Current Time: Thu Apr 24 22:48:48 EDT 2025

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

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

Back to the top