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)
Changing the background image of a chart dynamically
D_Petrov
<p>Greetings to all,</p>
<p>
I'm newbie here and in BIRT designing.</p>
<p>I have BIRT report with two charts and few datasets from SQL server DB.</p>
<p>The problem is , that I want to change the background image of one of the charts, depending from a string value from one of the datasets. Images are added as embedded in the project.</p>
<p>So if the value is green-> the chart background should be green, otherwise will be red.</p>
<p>it should be done with some custom scripting, I guess because I do not see any option for dynamic image in the Chart background. Can you help me?</p>
<p> </p>
<p>Best,</p>
<p>D_Petrov</p>
Find more posts tagged with
Comments
pricher
<p>Hi,</p>
<p> </p>
<p>If you are new to BIRT, I would highly recommend to avoid chart scripting because it can be a bit overwhelming. Reading your post, I think you can simply use the Visibility attribute to select which of the red or green chart will be displayed at run time.</p>
<p> </p>
<p>I am sending you a sample report that shows first the No Scripting approach. The 2 charts at the top are embedded in a 2-row grid. The Visibility attribute is set on the row and the condition is based on a report parameter (in your case, you could based the condition on a data set value).</p>
<p> </p>
<p>The chart at the bottom uses scripting, if you ever need an example. Please note that chart scripting is applied at render time, hence you do not have access to the data set anymore. For that reason, any value that you need from the data set must be passed as a global variable and recovered from the report context.</p>
<p> </p>
<p>Hope this helps,</p>
<p> </p>
<p>P.</p>
D_Petrov
<p>Hi pricher,</p>
<p> </p>
<p>Many thanks for the propositions! I`ll try it and tell you the result.</p>
<p> </p>
<p>Best regards,</p>
<p>D_Petrov</p>
D_Petrov
<p>I have two more questions about the chart script:<br>
1 How to target the embedded image in the script?</p>
<p>2 How to get a value from a column in a dataset in the script?</p>
<p> </p>
<p>Best,</p>
<p>D_Petrov</p>
pricher
<p>Hi,</p>
<p> </p>
<p>Off hand, I don't know how to embed an image through script.</p>
<p>As for getting the value of a column in the script, I mentioned in my previous post that chart scripting is executed at render time; therefore, you will not have access to the data set anymore. If you need access to a data set value while in the chart script, you need to store that value in a persistent global variable, and retrieve that value from the report context in the chart scripting. I have used a similar method in my previous example. Look at the report initialize method to see how I store the value of the report parameter into a persistent global variable. Then, in the chart scripting, I retrieve the value in the first statement of the beforeGeneration method.</p>
<p> </p>
<p>Again, I strongly recommend that you look at other methods than chart scripting to solve your problem. Based on what you explain initially, using the Visibility attribute should work well.</p>
<p> </p>
<p>Regards,</p>
<p> </p>
<p>P.</p>
D_Petrov
<p>Thank you! <span><span>I managed to</span> <span>fix it
</span></span></p>
<p> </p>
<p>Regards,</p>
<p>D_Petrov</p>