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 (
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.
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.
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.
Next I come back to the main report. I right click on the subreport and choose “Change Subreport links”.
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.
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.
When I look at the preview of my main report, a hyperlink appears below each the marks of each student.
When I click on the hyperlink, the chart opens for the corresponding student.
- A subreport is a report within a report. You can insert a subreport from the Insert Menu option: Insert—>Subreport.
- 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.
- 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.