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)
How to fix the bar size in a Bar chart.
Aarti
Hi,
I am using BIRT v2.5 in which i have designed a report containg bar chart.
The X-axis represents Category and Y-axis represents Balances of the bar chart.
Please find attached screenshots for your reference.
In screenshot 'Final_2.JPG', every bar represents Balance value for every category.
In screenshot 'Final_1.JPG', Balance values are NULL for other categories. Hence, no bar is shown in the bar chart. And the bar size for 'Rate' category is doubled.
What I am looking for is that, even if the values are NULL I want to display the category names on the X-axis with no bar and the bar size shoulg be fixed. (For example, the bar size should not double like shown in screenshot 'Final_1.JPG', it should maintain same bar size like shown in screenshot 'Final_2.JPG')
Any comments/inputs will be of great help.
Thank You.
Find more posts tagged with
Comments
mwilliams
In your case, it looks like you'd just need to make sure that all values are represented in your chart data. If you're only returning values that are not null, you'll have to have another dataSet that contains all the grouping values to join with your actual dataSet, so that all grouping values are represented. Let me know if you need help with this or need a better explanation!
Aarti
Hi MWilliams,
Thanks for your response!
Yes, it will be of great help if you could explain in brief to understand better.
cbelsole
<blockquote class='ipsBlockquote' data-author="'Aarti'" data-cid="96606" data-time="1330068876" data-date="24 February 2012 - 12:34 AM"><p>
Hi MWilliams,<br />
<br />
Thanks for your response!<br />
<br />
Yes, it will be of great help if you could explain in brief to understand better.<br /></p></blockquote>
<br />
I think he is saying that you need to substitute the null values with something so that it shows in the chart. You could possibly put a zero value whenever you see a null value. That would give it a number to show up in the chart.
mwilliams
Yes. That is pretty much correct. I'll give you an example, using your charts above.
In the chart that has all 5 groups represented, you have 50bps, 10bps, Rate, 1-10bps, and 11-50bps. You also have an optional grouping for Test/Rest. So, your data would look something like:
Field | Value | Test/Rest
50bps | 5 | Test
50bps | 7 | Rest
10bps | 35 | Test
10bps | 25 | Rest
Rate | 33 | Test
Rate | 46 | Rest
1-10bps | 22 | Test
1-10bps | 19 | Rest
11-50bps | 7 | Test
11-50bps | 6 | Rest
In the other chart, you've only returned a single field:
Field | Value | Test/Rest
Rate | 19 | Test
What you need in this case to have the same spacing as the other chart and same legend is:
Field | Value | Test/Rest
50bps | 0 | Test
50bps | 0 | Rest
10bps | 0 | Test
10bps | 0 | Rest
Rate | 19 | Test
Rate | 0 | Rest
1-10bps | 0 | Test
1-10bps | 0 | Rest
11-50bps | 0 | Test
11-50bps | 0 | Rest
To do this, you would just need to create a scripted dataSet or a flat file dataSet or something that always returns the rows:
Field | Value | Test/Rest
50bps | 0 | Test
50bps | 0 | Rest
10bps | 0 | Test
10bps | 0 | Rest
Rate | 0 | Test
Rate | 0 | Rest
1-10bps | 0 | Test
1-10bps | 0 | Rest
11-50bps | 0 | Test
11-50bps | 0 | Rest
You would then join or union this dataSet with your actual dataSet, which only has one row. This would give you a dataSet with a representation for all 10 rows, like you need. If using a joint dataSet, you'll have to create computed columns to merge the data so that you use the 0 value when there is no original value. You could probably do all of this in your query, if using a SQL dataSet.
Hopefully this explanation is better. Let me know your BIRT version, if you need an example.
Aarti
Thank you.. I had this solution in my mind..Working on it
<br />
One more workaround on this could be instead of showing the fields with zero values (rendered as null values from the database), I can just show the field which does not return null value. For example, my data would look something like:<br />
<br />
<br />
Field | Value | Test/Rest<br />
Rate | 19 | Test<br />
<br />
But by showing only one field value in the chart, I don't want its bar size to be doubled as shown in the second chart attached in my first post above.<br />
How can I fix the bar size irrespective of number of fields that have values?<br />
<br />
Regards,<br />
Aarti<br />
<br />
<br />
<blockquote class='ipsBlockquote' data-author="'mwilliams'" data-cid="96653" data-time="1330109777" data-date="24 February 2012 - 11:56 AM"><p>
Yes. That is pretty much correct. I'll give you an example, using your charts above.<br />
<br />
In the chart that has all 5 groups represented, you have 50bps, 10bps, Rate, 1-10bps, and 11-50bps. You also have an optional grouping for Test/Rest. So, your data would look something like:<br />
<br />
Field | Value | Test/Rest<br />
50bps | 5 | Test<br />
50bps | 7 | Rest<br />
10bps | 35 | Test<br />
10bps | 25 | Rest<br />
Rate | 33 | Test<br />
Rate | 46 | Rest<br />
1-10bps | 22 | Test<br />
1-10bps | 19 | Rest<br />
11-50bps | 7 | Test<br />
11-50bps | 6 | Rest<br />
<br />
In the other chart, you've only returned a single field:<br />
<br />
Field | Value | Test/Rest<br />
Rate | 19 | Test<br />
<br />
What you need in this case to have the same spacing as the other chart and same legend is:<br />
<br />
Field | Value | Test/Rest<br />
50bps | 0 | Test<br />
50bps | 0 | Rest<br />
10bps | 0 | Test<br />
10bps | 0 | Rest<br />
Rate | 19 | Test<br />
Rate | 0 | Rest<br />
1-10bps | 0 | Test<br />
1-10bps | 0 | Rest<br />
11-50bps | 0 | Test<br />
11-50bps | 0 | Rest<br />
<br />
To do this, you would just need to create a scripted dataSet or a flat file dataSet or something that always returns the rows:<br />
<br />
Field | Value | Test/Rest<br />
50bps | 0 | Test<br />
50bps | 0 | Rest<br />
10bps | 0 | Test<br />
10bps | 0 | Rest<br />
Rate | 0 | Test<br />
Rate | 0 | Rest<br />
1-10bps | 0 | Test<br />
1-10bps | 0 | Rest<br />
11-50bps | 0 | Test<br />
11-50bps | 0 | Rest<br />
<br />
You would then join or union this dataSet with your actual dataSet, which only has one row. This would give you a dataSet with a representation for all 10 rows, like you need. If using a joint dataSet, you'll have to create computed columns to merge the data so that you use the 0 value when there is no original value. You could probably do all of this in your query, if using a SQL dataSet.<br />
<br />
Hopefully this explanation is better. Let me know your BIRT version, if you need an example.<br /></p></blockquote>
mwilliams
Oh, so you aren't wanting to show the category values even when they are null?
Would re-sizing the chart be an option? Or are you wanting the chart to have the same dimensions no matter what? If re-sizing would work for you, take a look at this devShare post:
http://www.birt-exchange.org/org/devshare/designing-birt-reports/1409-resize-bar-chart-based-on-the-number-of-bars/
If that won't work for you, then you might do something similar as to finding how many bars are in the chart and then adjusting the unitSpacing in the beforeGeneration accordingly.