Amazon festival offer

Sunday 19 May 2013

Splitting a bar chart into multiple pages in iReport or JasperReport Server


Sometimes you may need to split the chart into multiple pages as the Category Expressions dataset is huge, which is resulting the graph to be in an unreadable format.
Therefore, you may want something like, the Category Expression dataset to be distributed in blocks of 10, as to display first 10 categories in page1, and so on.
Steps to achieve this:-
1.      Open your report in iReport. The report query is the main report query, in my sample I                                     
 will refer to two fields: cat_exp as category and val_exp as value.
    2.   In the Report Inspector right click on the report and select Add Report Group.                        
          It will open a New group wizard
          Enter Group Name: - chartsplitter
          Select Group by the following report object:- 
                                $V{REPORT_COUNT} - 1 - ( ($V{REPORT_COUNT} - 1) % 10   
      Click next and select Add the group footer.
3.      Drag and drop a chart from the Palette into the report designer on the group footer band. Select Bar Chart, follow the Category Chart Wizard:
v  Choose Main report dataset from Dataset Click Next.
v  Change Series expression to what you need (e.g. "Sample"), Click Next.
v  Set Category expression to $F{cat_exp}
v  Set Value expression to $F{val_exp}.Click Finish.
4.      Right click on the chart, click on Chart Data. In the Dataset tab set Reset type to Group, select as Reset group your group chartsplitter. Click close.

I have attached a sample output where I set the splitter value to 3 on a sample dataset.



Recommendation 1: Select the chart and scroll in the Properties panel to Range Axis Max Value Expression, set the max value for your chart there. This will ensure that all charts will have the same scale. In the attached sample I have set it statically to 100, it'd be also good to provide the max value via database query.
Recommendation 2: When you run the report you might notice that the last bar chart might look different as JasperReports/jfreechart scales the width of the bars depending on the number of categories. To have a static width for the bar charts you'd need to create a chart customizer which sets a fixed width to a single bar.

4 comments:

Sadakar Pochampalli said...

Awesome ...!!!!

Give me your gmail id buddy :)

http://jasper-bi-suite.blogspot.in/

Sadakar Pochampalli said...

Gret Work ...!!!

Unknown said...

How do I do this with a custom Dataset?

Unknown said...

How do I do this with a custom Dataset?