Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Archived » BIRT » Histogram with dynamically computed number of bars
Histogram with dynamically computed number of bars [message #673630] Tue, 24 May 2011 09:31 Go to next message
Eclipse UserFriend
Originally posted by:

Hi,

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
simpler way.

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:

axis.getScale().setStep(step);
seriesDefinition.getSeries().get(0).getDataDefinition().get(0).setDefinition(
"(BirtMath.roundDown(row[\"value\"]/"+step+",0)+0.5)*"+step);
seriesDefinition.getGrouping().setGroupingInterval(step);

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?
Re: Histogram with dynamically computed number of bars [message #673655 is a reply to message #673630] Tue, 24 May 2011 11:14 Go to previous messageGo to next message
Tomas Greif is currently offline Tomas GreifFriend
Messages: 53
Registered: September 2010
Member
Maybe you can add computed columns to the dataset and link the calculation to the parameter. Attached is an example where you are able to set number of columns you would like to see in histogram as a parameter.
Tomas
Re: Histogram with dynamically computed number of bars [message #673827 is a reply to message #673655] Tue, 24 May 2011 21:00 Go to previous message
Eclipse UserFriend
Originally posted by:

On 05/24/2011 01:14 PM, TomasGreif wrote:
> Maybe you can add computed columns to the dataset and link the
> calculation to the parameter. Attached is an example where you are able
> to set number of columns you would like to see in histogram as a parameter.
> Tomas

Thanks Tomas, after modyfying your idea a little bit, I managed to get
what I wanted :)

Michal
Previous Topic:Excel as a datasource
Next Topic:Scripted data set
Goto Forum:
  


Current Time: Fri Mar 29 05:51:27 GMT 2024

Powered by FUDForum. Page generated in 0.02257 seconds
.:: Contact :: Home ::.

Powered by: FUDforum 3.0.2.
Copyright ©2001-2010 FUDforum Bulletin Board Software

Back to the top