Skip to Content

Version Information: This sample is prepared with Crystal Reports 2008

Creating a chart using Subreport:

This is a continuation to my previous blogs on Crystal Reports Charts (

http://scn.sap.com/community/crystal-reports/blog/2012/04/30/using-charts-in-crystal-reports-part-1

http://scn.sap.com/community/crystal-reports/blog/2012/05/01/using-charts-in-crystal-reports-part-2)

I will continue with the same sample data. In the previous example I had created a single chart showing the total marks obtained by all the students and also a chart showing marks obtained in different subjects by a single student.

/wp-content/uploads/2012/05/chart1_98001.jpg

In this blog I will demonstrate how to use a subreport to display a chart.

 

I will create a new subreport by clicking on Insert -Subreport-Create a subreport with the Report Wizard. I have selected the option for On-demand subreport.

/wp-content/uploads/2012/05/chart12_98002.jpg

When I click on the Report Wizard , I can choose the datasource for the report. As the datasource for the parent and child report is identical in this case, I choose the same database and tables. When I click on “Next” button, I can link the tables. This is also done identical to the main report. Then I click on “Finish” and “OK” and insert the subreport in a new Group Footer section of main report.

Next I create a parameter in the subreport . This will be necessary to link the student in the group of the main report to the data in the subreport.

/wp-content/uploads/2012/05/chart13_98042.jpg

  Next I come back to the main report. I right click on the subreport and choose “Change Subreport links”.

/wp-content/uploads/2012/05/chart14_98043.jpg

  I link the parameter created in subreport to the student details in main report. This link should be based on the primary key(s) . In my demo data the student name is unique, so I have used the same to link the main report to the subreport.

/wp-content/uploads/2012/05/chart15_98044.jpg

I create the chart in the report header of the subreport. The student name , for whom the report is created, in displayed in a separate report header. All other sections are suppressed.The method of creation of the chart is similar to my previous blog.

/wp-content/uploads/2012/05/chart16_98048.jpg

When I look at the preview of my main report, a hyperlink appears below each the marks of each student.

/wp-content/uploads/2012/05/chart17_98049.jpg

When I click on the hyperlink, the chart opens for the corresponding student.

/wp-content/uploads/2012/05/chart18_98050.jpg

Note:

  1. A subreport is a report within a report. You can insert a subreport from the Insert Menu option: Insert—>Subreport.
  2. A linked subreport is a subreport whose data is coordinated with the parent subreport. Here I will use a linked subreport to ensure that the chart in the subreport is created for the relevant student.
  3. On-demand subreport ensures that data is fetched for the subreport as and when required. The subreports appear only as hyperlinks. It is advisable to use On-demand subreports when many subreports are linked to one main report.
To report this post you need to login first.

1 Comment

You must be Logged on to comment or reply to a post.

Leave a Reply