Home » Archived » BIRT » Charts: What are scripts for?
Charts: What are scripts for? [message #85261] |
Fri, 28 October 2005 09:41  |
Eclipse User |
|
|
|
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 #86894 is a reply to message #86556] |
Thu, 03 November 2005 08:19   |
Eclipse User |
|
|
|
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 #86924 is a reply to message #86894] |
Thu, 03 November 2005 09:35   |
Eclipse User |
|
|
|
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   |
Eclipse User |
|
|
|
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   |
Eclipse User |
|
|
|
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 #87178 is a reply to message #87060] |
Thu, 03 November 2005 11:25   |
Eclipse User |
|
|
|
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 #87461 is a reply to message #87163] |
Fri, 04 November 2005 05:57   |
Eclipse User |
|
|
|
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!
|
|
| | |
Finally I found out what the problem was! Yeah!!! [message #89612 is a reply to message #88485] |
Thu, 10 November 2005 06:29  |
Eclipse User |
|
|
|
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><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
|
|
|
Goto Forum:
Current Time: Thu Apr 24 22:48:48 EDT 2025
Powered by FUDForum. Page generated in 0.05230 seconds
|