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)
total sum in a pie chart
system_migrated
Hello,
I'm using BIRT since 3 weeks. First it was in order of my team leader, but now I like using BIRT. I learned a lot about SQL, Java Script and chart creation as itselfs.
Now I have a more or less big problem, and I couldn't find a solution via forum search and google (or maybe I missed something). I created a pie chart, based on an PostgreSQL database. It works good, but my supervisor wants to have an additional information on it: the total sum of the values in the chart as a part of the title.
E.g.: The pie chart has 4 parts: 3 hrs, 5 hrs, 2 hrs and 2 hrs. Now I have to add "(total time: 12 hrs)" to the title.
At the moment i work with a fake: I add these information with a small script.
For the moment it works but the data will change in future and I have no time to change the script every time. So I have to find out how to sum the four values.
How can I solve this problem? Btw: I'm not only a beginner with BIRT but also with Java script, so I need a more detailed answer so that I can understand the solution.
Thanks for your help,
jsOpa
Find more posts tagged with
Comments
mwilliams
Hi jsOpa,
If your chart contains all the data from your dataSet, you can do something like the following.
In your initialize method of your report, put:
cTotal = 0;
In your onFetch method of your dataSet, put something like:
cTotal = cTotal + row["yourField"];
reportContext.setPersistentGlobalVariable("chartTitle", cTotal.toString());
Then, in your chart's script, put:
function beforeDrawBlock( block, icsc )
{
icsc.getChartInstance().getTitle().getLabel().getCaption().setValue(icsc.getExternalContext().getScriptable().getPersistentGlobalVariable("chartTitle"))
}
This will put the total for the field you summed in your onFetch script into the title of the chart.
Hope this helps.
Migrateduser
Hi Michael,
thanks for your help. It works very fine, and my supervisor is also happy (for the moment) :-)
cu, jsOpa
mwilliams
Glad to help! Let us know whenever you have questions!