| 
| Histogram with dynamically computed number of bars [message #673630] | Tue, 24 May 2011 05:31  |  | 
| Eclipse User  |  |  |  |  | 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 #673827 is a reply to message #673655] | Tue, 24 May 2011 17:00  |  | 
| Eclipse User  |  |  |  |  | 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
 |  |  |  | 
Powered by 
FUDForum. Page generated in 0.02549 seconds