|Histogram with dynamically computed number of bars [message #673630]
||Tue, 24 May 2011 09:31
Originally posted by: |
I'm trying to create a histogram ie. a chart showing a distribution of
data coming from a data set. To avoid changing the data set itself I
- defined category series using formula
(BirtMath.roundDown(row["value"] / 5, 0) + 0.5) * 5
where 5 is the width of each bar/interval in category units
- enabled grouping of type "numeric" with interval set to 5 and
"Average" as an aggregate function
- defined value series using aggregate function "Sum" and formula "1"
- set x axis scale interval to 5.
This effectively puts a bar at the center of each interval with height
corresponding to the number of values in that interval. You can see it
in the report attached. I'd be glad to hear if this can be done in a
Now, to avoid the clutter I'd like to dynamically change the width of
interval so that:
- it is either 5 or a multiple of 10,
- the number of bars is between 8 and 16.
First I tried to write a script for chart's beforeDataSetFilled()
function, but it seems that the data is already grouped by the time this
function is called.
So instead I wrote scripts for data set's beforeOpen(), onFetch() and
beforeClose() functions with an intention of calculating minimum and
maximum value from the data set and then modifying the chart's
properties before it is processed. You can see those scripts in the
attached report, note that part of beforeClose() is commented out.
The idea was to set category series formula, grouping interval and scale
interval using the following three lines of code:
Unfortunately it doesn't seem to have any effect at all! Is it because
the data for the chart is already processed at that time?
How can I achieve the behaviour described above?
Powered by FUDForum
. Page generated in 0.01908 seconds