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)
Date Chart - Dynamically change minor grid count based on major grid
jakoby84
Hello,
I have the following problem: I have reports with line charts which are deployed in a Servlet. The user can filter the data so sometimes the chart displays data of 1 week, sometimes data of several months.
In general I do like how BIRT dynamically creates the major grid tick count but on the other hand this is also my problem:
The customer I'm working for wants minor grid ticks for every day when the major grid represents weeks (and minor ticks for weeks if major grid = month etc). So I can set minor grid count to 7, which yields the correct result for this case. But when more/less data is displayed the minor ticks are still 7 and I get a tick for every second day, or if less data is shown, it shows a tick for every seventh of a day. And so on. I think you get the point.
I did some research but can't really figure out how to adjust the minor grid count programmatically. The approach would be to fill the chart with data, check the spacing of the major grid (e.g. 1 week or 2 days or 1 day etc.), and then set the minor grid count to a respective value.
But I can't figure out which chart objects / methods I have to use for that.
Any help is appreciated!
Kind regards and thanks in advance, Jakob
PS: A small not really related question (let me know if I should open a new topic for it):
The values are determined by a count() function in the chart's 'Select Data' tab. If there is no data for one particular day, the chart doesn't display it. Is it possible to have a count of zero instead, so the chart would also display the zero values?
First picture: Minor Grid count inappropriate because major grid = 2 weeks
Second picture: Minor Grid count appropriate because major grid = 1 week
Find more posts tagged with
Comments
mwilliams
Is there any way you can reproduce what you're doing, in a report that uses the sample database? This way I can see everything you're doing and be able to test with it? Thanks!
jakoby84
Hello mwilliams and thanks for offering your support.
I recreated the chart with the sample database. Of course with the data in it, it is not so meaningful, but the axis is what matters...
To reproduce run the report with start date 2003-01-01 and end date 2003-02-01. As desired, each minor grid tick represents one day. Then run the report again with start date 2003-01-01 and end date 2003-04-01. As each major grid tick now represents two weeks but the minor grid count is still 7, a minor grid tick now represents every 2nd day...
mwilliams
This could be fixed up to be better, but take a look at the chart script. It takes the parameter values, determines the days and months between the dates. The step value becomes equivalent to the number of months with a unit of weeks. So, with data that includes Jan and Feb, your step would be 2 weeks, etc. The number of ticks seemed to get messed up (some missing or extra ones) if I didn't have an even number of steps, so I computed new values for the min and max to keep your originally selected range centered, but so that you had an even number of weeks. Like I said, this is just a rough draft, so you might be able to clean it up some.
To see the difference, try Jan 1, 2003 - Jan 31, 2003. Then, try Jan 1, 2003 - Feb 28, 2003. Also, try a longer range, like Jan 1, 2003 - Apr 30, 2003. Let me know if you have questions.
jakoby84
Hi mwilliams,
thanks alot for the exhaustive reference implementation and your input in general. I have to further customize the script because I furthermore change the grouping between hours, days, weeks and months based on the given time period. But with your script, I got a very got starting point to do so.
The script override the autoscale algorithms; I hope that I won't regret to go this way, because this way I have to account for all possible exceptions by myself. But anyways, I hope it will all work out well.
Thanks, see ya, Jakob
mwilliams
You're welcome. The reason I had to change the scale was that when setting the minor grid in script, it seemed to run off the edge of the chart, if the set of groupings was not even. You could possibly find a way to manage this differently. I chose to pad the dates on the chart, but there might be a better way, for your situation. Let me know if this is an issue and you need help looking further into another option.
jakoby84
<blockquote class='ipsBlockquote' data-author="'mwilliams'" data-cid="114148" data-time="1360707405" data-date="12 February 2013 - 03:16 PM"><p>
You're welcome. The reason I had to change the scale was that when setting the minor grid in script, it seemed to run off the edge of the chart, if the set of groupings was not even. You could possibly find a way to manage this differently. I chose to pad the dates on the chart, but there might be a better way, for your situation. Let me know if this is an issue and you need help looking further into another option.<br /></p></blockquote>
<br />
Yes the minor grid running off the edge is kind of strange. Well, I will go with the padding as well. It seems to be the same (in a programmatical way) as the 'auto expand' option in the scale dialog. So probably there really isn't a better way...
mwilliams
Good enough! Well, let me know if you run into any other issues with this!