Home
Analytics
Adding weekly totals as floating label in bar chart
jlweb58
<p>Hello, I'm new to BIRT; my company is evaluating its use for the generation of reports in the healthcare industry. My background is as a Java developer and Eclipse user, I'm trying out the newest version of the Eclipse BIRT Report Designer (4.4.0 Luna).</p>
<p> </p>
<p>One of the charts I'm trying to reproduce (or port) from PowerPoint to BIRT has stacked bar charts showing integers for three series over a period of four weeks. The ppt chart has a bubble label with the weekly total for one of the series floating above the series. Is there any way of accomplishing that with BIRT? Ideally the weekly total should be calculated on the fly. I've attached an image to show what we're trying to do.</p>
<p> </p>
<p>Thanks in advance!</p>
Find more posts tagged with
Comments
pricher
<p>Hi,</p>
<p> </p>
<p>Out of the box, you will not be able to add floating labels to your chart. You could probably do it by using chart scripting, but since you are new to BIRT, I would try to avoid this option as it can get quite complicated based on your scenario.</p>
<p> </p>
<p>One another way to do it, without code or scripting, is to put a grid at the top of your charts where you can calculate the sums. In the attached report, I have created a basic chart using a data set based on Classic Models. The X-Axis is grouped on months, and there is a Y-Axis grouping on product line. On top of the chart, I have put a grid with one table in each cell. Each table has a group on date year, and I have added an aggregation to sum up cnt only for Classic Cars. In order to display only one line in each table, I created a counter (rowCnt) on the onCreate event of the table, which I increment in the onCreate event of the group header. Finally, I turn off the visibility of the group header by using the value of rowCnt in the condition.</p>
<p> </p>
<p>Maybe this will fit your needs.</p>
<p> </p>
<p>Regards,</p>
<p> </p>
<p>P.</p>
<p> </p>
<p> </p>
jlweb58
<p>Thanks pricher, that's helped me get a good start. I don't suppose there's any way of formatting the total cells to have an elliptical border? I'm not afraid of scripting - if you could point me to a couple of URLs with good documentation of the scripting API that would be very helpful. I haven't turned up much via Google yet.</p>
<p> </p>
<p>Our ultimate scenario will be to generate reports automatically from a Java application running in Tomcat after an ETL process to fill the database.</p>
<p>
Regards,</p>
<p> </p>
<p>J.</p>
pricher
<p>You can use CSS to create an elliptical border. In the sample I have sent you, replace the 2 data items in the grid above the chart with text items. Make sure you change the format of the text items to HTML (drop down at the top) and use the following code:</p>
<p> </p>
<p><span style="font-family:'courier new', courier, monospace;"><div style="border:1px solid #a1a1a1;background:#dddddd;width:50px;border-radius:40px;"><br>
<VALUE-OF>row["rslt"]</VALUE-OF><br>
</div></span></p>
<p> </p>
<p>The documentation for the chart scripting API is a bit all over the place... One good start is this page: <a data-ipb='nomediaparse' href='
http://birtworld.blogspot.fr/2010/08/birt-charting-scripting-overview.html'>http://birtworld.blogspot.fr/2010/08/birt-charting-scripting-overview.html</a></p>
;
<p> </p>
<p>Good luck and don't be afraid to post more questions!</p>
<p> </p>
<p>P.</p>
jlweb58
<p>Using CSS works very nicely, thanks! WIth the four-week range in the thumbnail above I'm having a problem getting the grouping to work correctly - I group on a datetime field with an interval of one week; but every column in my report groups the values from the first calendar week. I looked at your two table groups, but couldn't see anything that you really did differently. In your sample you have data from two consecutive years and the sum for each year is shown in the respective cells in the grid. I'm obviously missing something here.</p>
pricher
<p>Here's an updated report design that is closer to your original report. This time, I am using a flat file with daily data for for weeks, starting on a Sunday.</p>
<p> </p>
<p>The chart is now grouped on Days to show one stacked bar for each day.</p>
<p> </p>
<p>The grid above the chart has now 4 tables, one for each week. Each table has a grouping on date with a week interval and a data binding called "rslt" that sums up the value per week for Classic Cars. Each table would display four rows since there are 4 weeks worth of data. To show only one week per table, I use the Visibility attribute of the Group Header row to hide all but the week I need to display. For that, I have a row counter that increment each time a group header row is created, and I test in the Visibility attribute.</p>
<p> </p>
<p>I understand this design is a bit crude and will fit scenarios where the number of weeks in the chart is fixed. If you need more flexibility, some scripting will be involved. But since you are new to BIRT, I thought a "no-code" solution might be better for now...</p>
<p> </p>
<p>Enjoy!</p>
<p> </p>
<p>P.</p>
jlweb58
<blockquote class="ipsBlockquote" data-author="pricher" data-cid="130276" data-time="1408629853">
<div>
<p>To show only one week per table, I use the Visibility attribute of the Group Header row to hide all but the week I need to display. For that, I have a row counter that increment each time a group header row is created, and I test in the Visibility attribute.</p>
</div>
</blockquote>
<p> </p>
<p>That was exactly what I needed! The link you mentioned above is very helpful; with its help I figured out how to format my date axis like this: "KW 16 (14.4 - 20.4.)". Now I need to figure out how to tell the Report Designer that my locale is Locale.GERMANY, where the week begins on Monday. That can't be too hard, Google is my friend...
</p>
<p> </p>
<p>Thanks,</p>
<p> </p>
<p>J.</p>
pricher
<p>Hi,</p>
<p> </p>
<p>Changing the locale will not change the way dates are grouped in weeks... It will just change the format used to display them.</p>
<p> </p>
<p>I have modified another time my design to fool the way tables are grouped by week. I simply added a computed column to subtract one day to the original date. So, the chart is grouped on day and will start now on Monday (use the new csv file...) and the tables are grouped by week on the computed date field.</p>
<p> </p>
<p>BTW, you can change the locale of BIRT two ways: in the startup command, add -nl de_DE, or in Window --> Preferences --> Report Design --> Preview, you can change the locale for the Viewer.</p>
<p> </p>
<p>P.</p>
jlweb58
<p>Yes, that worked. I don't quite understand why that should be necessary - my Eclipse environment is set to the proper locale, de_DE was already set in the Preview preferences.</p>