Discussions
Categories
Groups
Community Home
Categories
INTERNAL ENABLEMENT
POPULAR
PUBLIC CLOUD
PRIVATE CLOUD
Quick Links
MY LINKS
HELPFUL TIPS
Back to website
Home
Intelligence (Analytics)
Access to computed column value in onRender script?
Marko
Hi!
I'm working on one report and I'm trying to make gradient color bars in result chart.
I'm doing this with this code: fill.set(63, 101, x). Variable x is reducing in every cycle, or in other words, every bar has blue value in RGB triplet little smaller.
E.g. bar1 - 63,101, 250, bar2 - 63,101, 240, bar3 - 63,101, 230, and etc.
Problem is that I need to know total number of all bars in result chart so I can dynamically change bar colour depending on bar number. For example: If I enter some constant value which will reduce RGB value, let say 5, than bar colors will be gradient when I have 40 bars in result chart, but when I have 5 bars in result chart, then bar colours of that 5 bars won't be noticeable.
Is there any other way to get total row number in onRender script, because I can't get computed column value in onRender script. I tried also with set and get PersistentGlobalVariable function, but like before, with no result.
Thanks in advance for any suggestion,
Marko
Find more posts tagged with
Comments
mwilliams
Hi Marko,
How did you go about trying to use the PersistentGlobalVariable?
Marko
<blockquote class='ipsBlockquote' data-author="mwilliams"><p>Hi Marko,<br />
<br />
How did you go about trying to use the PersistentGlobalVariable?</p></blockquote>
<br />
Hi Michael,<br />
<br />
I'm sure it's not hard to guess that I'm total beginner in this, so I'm trying to use everything that comes on my mind. Sometimes too much.
<br />
<br />
Thanks anyway,<br />
<br />
Marko
mwilliams
Marko,
The reason I asked is because you should be able to grab this value from a computed column in your dataSet that counts the number of rows, then store this value in a PGV, and then grab it in the chart script to do your computing. So, I wanted to know what you did so that I could help modify it to work for you.
Marko
<blockquote class='ipsBlockquote' data-author="mwilliams"><p>Marko,<br />
<br />
The reason I asked is because you should be able to grab this value from a computed column in your dataSet that counts the number of rows, then store this value in a PGV, and then grab it in the chart script to do your computing. So, I wanted to know what you did so that I could help modify it to work for you.</p></blockquote>
<br />
Hi,<br />
<br />
I misinterpreted your question so I felt little ashamed after that. :-), but I'm ready now for the next round of asking silly questions.<br />
<br />
In Body part, I only have chart and data element. In data element (onPrepare script) I have put this code:<br />
<br />
reportContext.setPersistentGlobalVariable("TotalNumberOfRows", NoOfRows); where NoOfRows refer to computed column variable name.<br />
<br />
Now, I'm not sure how to grab that value from PGV in onRender script... I try writing:<br />
var reduce = getPersistentGlobalVariable("TotalNumberOfRows"); <br />
which throws this error: <br />
Chart NewChart: <br />
+ Cannot convert NaN to java.lang.Integer at line 31 of chart script:' <br />
<br />
Obviously because, it handovers null value to the reduce variable.<br />
<br />
Then I try to insert this line of code:<br />
var reduce = reportContext.getPersistentGlobalVariable("TotalNumberOfRows");<br />
Now it said that reportContext is not initialized and I'm aware of that, so I would be really thankful if you can give me some advice for next step how to grab that value in onRender script from PGV.<br />
<br />
Thank you for your effort and patience,<br />
<br />
Marko<br />
<br />
P.S.<br />
<br />
I try using this line of code in onRender script. I saw and example here: <a class='bbc_url' href='
http://www.birt-exchange.org/forum/designing-birt-reports/14407-report-parameter-scripting.html'>http://www.birt-exchange.org/forum/designing-birt-reports/14407-report-parameter-scripting.html</a><br
/>
<br />
var reduce = icsc.getExternalContext().getScriptable().getPersistentGlobalVariable("TotalNumberOfRows");<br />
<br />
Before that I have put line in onPrepare script in Data element:<br />
reportContext.setPersistentGlobalVariable("TotalNumberOfRows", NoOfRows); where NoOfRows is the name of computed column variable.<br />
<br />
That also didn't work and gave me error message that NoOfRows is not defined. If I put row("NoOfRows"), then I get message that row is not defined.
mwilliams
Marko,
The icsc.getExternalContext().getScriptable().getPersistentGlobalVariable("TotalNumberOfRows"); call is correct.
For setting it, try using the following in the data element's onCreate script:
reportContext.setPersistentGlobalVariable("TotalNumberOfRows", row["NoOfRows"]);
This should work if the data element is bound to the dataSet. If you have issues, let me know.
Marko
Hi!<br />
<br />
Once again thank you for your answer, but when I try this, BIRT Report Viewer sends me this error message:<br />
<br />
<a class='bbc_url' href='
http://www.deviantpics.com/share-9D0D_4A9E8DFE.html'><img
src='
http://www.deviantpics.com/thumb-9D0D_4A9E8DFE.jpg'
alt='Posted Image' class='bbc_img' /></a><br />
<br />
I'm obviously doing something wrong but I don't know what.<br />
<br />
I'll write once again all the code I wrote:<br />
In BODY I have put Data element which is hidden and in here is NoOfRows. In Data element in OnPrepare script is this code:<br />
reportContext.setPersistentGlobalVariable("TotalNumberOfRows", row["NoOfRows"]);<br />
<br />
There is also chart element in the Body, which has onRender script with this code:<br />
var reduce = icsc.getExternalContext().getScriptable().getPersistentGlobalVariable("TotalNumberOfRows");<br />
<br />
I attached my report in hope that it might help.<br />
<br />
Marko
mwilliams
Marko,
Try this report design. Since I can't run it, I can't do simple tests on it. I used this.getValue() to set the PGV instead of row. Let me know.
Marko
<blockquote class='ipsBlockquote' data-author="mwilliams"><p>Marko,<br />
<br />
Try this report design. Since I can't run it, I can't do simple tests on it. I used this.getValue() to set the PGV instead of row. Let me know.</p></blockquote>
<br />
That was it!!
<br />
<br />
Thank you Michael for helping me.<br />
<br />
I'll write once again (for future searchers) the exact code that works in my report:<br />
<br />
setPGV in onCreate script:<br />
reportContext.setPersistentGlobalVariable("SomeName", this.getValue().toString());<br />
<br />
getPGV in onRender script:<br />
icsc.getExternalContext().getScriptable().getPersistentGlobalVariable("SomeName");<br />
<br />
Marko