Some Eclipse Foundation services are deprecated, or will be soon. Please ensure you've read this important communication.

Bug 193914

Summary: Change chart size dynamically
Product: z_Archived Reporter: maria baldassarri <mbaldass>
Component: BIRTAssignee: Yulin Wang <Lionel.wyl>
Status: VERIFIED WORKSFORME QA Contact: Maggie Shen <lshen>
Severity: enhancement    
Priority: P3 CC: acc-clps, hchristensen, jerlich, sbouchet
Version: 2.1.2Keywords: plan
Target Milestone: 2.5.0   
Hardware: PC   
OS: Windows XP   
Whiteboard:
Attachments:
Description Flags
Design file example none

Description maria baldassarri CLA 2007-06-22 04:49:04 EDT
Hi, 
I'm working with Birt 2.1.2. I have a report in which I display a chart multiple times (it is inside a table group in a table). Each time, the chart inherit the dataset from the table, and displays its entries. The chart is a flipped bar chart. Is there a way to change dynamically the chart size in order to show different dataset sizes? 

For example, I have a data set with 2 columns NAME, VALUE, and a table grouped by NAME. Consider this case (VALUEs aren't important): 

NAME        VALUE 
a        1 
a        12 
a        41 
a        541 
a        61 
a        231 
a        41 
a        541 
a        1 
a        31 
a        1 
a        12 
a        11 
b        25 

In this case, my report will display 2 charts, one for "a" with 13 bars, and one for "b" with 1 bar. Is there a way to resize the chart in order to have small charts for small amounts of bars and higher charts for higher number of bars? In my case, the bar number varies from 1 to 200 ca.  Choosing a static size that allow 200 bars to be displayed clearly, will result in awful enormous charts in the case of only one bar.
It would be perfect to have control on the chart size by script (for example, changing the chart size in the onCreate of the table group), but also an auto-adaptive resizing would be valid too.
Comment 1 maria baldassarri CLA 2007-06-22 04:58:11 EDT
Created attachment 72137 [details]
Design file example
Comment 2 Bouchet Stéphane CLA 2007-08-08 08:41:00 EDT
Hi,

I ran into the same issue.

According to bug #159970, i can set the size of my chart on the 'beforeFactory' event, but i can't use any dataset result to set the size dynamically.

Cheers,

Stéphane
Comment 3 David Michonneau CLA 2007-09-05 04:34:11 EDT
I suggest to use an auto-adaptive size in such scenarios. The goal is to have a 
consistent bar width for all the charts coming from the same chart design, in 
repeater controls such as tables and crosstabs (in the future). I think this 
only make sense for chart with category axes. In such case, we could compute 
the max number of categories to show, and use the chart width as the base size, 
then compute the size of other charts by checking the ratio of the categories 
vs the max one. We have to experiment to check if only the plot should be 
resized or the whole chart (which would result in legends being misaligned).
Comment 4 Yulin Wang CLA 2008-05-04 00:22:01 EDT
We could add adaptive size support for chart in tables, just like chart in xtab.
However, we should add some limitations for chart, so the chart can align itself to the horizontal labels. For instance, chart should be with axes, flipped, no legend, not chart title, and so on.
We should add a property in model and UI to enable adaptive size, since this behavior is optional. Meanwhile, this property is disabled until all prerequisites are satisfied. Since it will result in model and UI change, and we are in 2.3 RC period, it should be fixed in next release.
Comment 5 erlich CLA 2008-08-13 10:44:59 EDT
I don't understand why the adaptative size cannot work with legend or title?
I need to be able to set the whole chart size dynamically according to the submitted parameters..
For example with a pie chart with lots of columns, the pie itself my show fine but the legend is clipped.. 
Can't something be done to make the whole chart size configurable dynamically ?
Comment 6 erlich CLA 2008-12-30 08:55:04 EST
Any update?
Comment 7 Yulin Wang CLA 2008-12-31 01:20:38 EST
(In reply to comment #5)
> I don't understand why the adaptative size cannot work with legend or title?
> I need to be able to set the whole chart size dynamically according to the
> submitted parameters..
> For example with a pie chart with lots of columns, the pie itself my show fine
> but the legend is clipped.. 
> Can't something be done to make the whole chart size configurable dynamically ?
> 

There are two solutions for this issue.
The first one is to let user set chart size by scripting. The final size computation will be done by user.
The second one is to let user set a base size such as bar width, just like the comment#3. This solution has many limitation just like the comment#4.
Which one could resolve your issue?
Comment 8 Yulin Wang CLA 2009-01-07 02:42:36 EST
I think currently chart supports dynamic size change by script. However user should compute size in script.
Please write script like this:

function beforeGeneration( chart, icsc )
{	
  // Get Y series definition. This is a sample for Bar chart.
  var ySD = chart.getPrimaryOrthogonalAxis(chart.getPrimaryBaseAxes()[0]).getSeriesDefinitions().get(0);
  // Get data point count
  var count = ySD.getRunTimeSeries().get(0).getDataSet().getValues().length;
  // Compute width and set it to chart block. Here we suppose bar width is 50 and legend width is 100
  chart.getBlock().getBounds().setWidth(50*count+100);
}

You could take this example to compute size by yourself.
Comment 9 Maggie Shen CLA 2009-01-13 03:08:35 EST
Tried the given script, the chart size can be set dynamically. Set the bug as verified.