Creating graphical representation data with crystal report in C#.net

No.of Views3326
Bookmarked1 times
Downloads 
Votes0
By  youngmurukan   On  15 Feb 2010 21:02:15
Tag : Crystal Reports , How to
Creating graphical representation data with crystal report in C#.net
emailbookmarkadd commentsprint

Images in this article missing? We recently lost them in a site migration. We're working to restore these as you read this. Should you need an image in an emergency, please contact us at info@codegain.com

 

Abstract:

Graphical representation of data always gives high readability and easy understanding to anyone. Therefore users may require some reports by graphs and charts. Crystal Reports has a powerful graphing and charting engine and it provides 36 different types of charting templates.

As I mentioned my previous article, Crystal Report provides four main general categories (layouts) of graphs.

1. Advanced 2. Group 3. Cross-Tab graphs 4. OLAP

This article focuses on creating chart report using 'Group layout'. My previous article focused reporting with 'Advanced Layout'. Future articles will focus the other layouts.

Technologies:

Crystal Report and Asp.NET

Language:

C#.net

Prerequisite:

SQL Server 2005, Visual studio 2005/2008, Crystal report

Here I am going to produce a report which represent, election results graphically. First you have to design a database. Create database name 'ElectionResults' with one table called 'Vote_Results'. (The same database which I used in my earlier article)

There are three columns in Vote_Results table.

Note: The database design is for demonstration purposes only.

Let us design a report using 'Group layout' in crystal report, get the total number of election results for political parties' for all districts.

For design the report, there are two standard ways. The first way is we can use the crystal report and second one is we can use the Visual studio. Here we are going to use Visual Studio.

Follow the steps which I mentioned my earlier article till you select the table of database. Now select the fields from the table as shown by below illustration.

Here Click 'Next' Button. You can see a screen as below.

Here select political_party field and click 'Finish'. If you follow all steps correctly, the result will be as follow. Our focus is to represent these data graphically. Therefore you need to hide/suppress the sections by right clicking on section headers.

Then from the menu select Crystal Report => Insert=> Chart. (As shown by the following figure)

Once you click that, system will give a screen like follow with many chart types. You can select any type of chart type from this list. If you uncheck 'Automatically set chart options' then you can see another two tabs will appear. Now I have selected 'Pie' chart and Select 'Pie chart with 3D visual effect' from right hand side.

Then go to the Data tab. Select 'On change of' , 'select destrict' field and 'political_party' fields from available fields. Then select 'votes_obtained' field as Show Value(s), shown by the following figure. Here you can see 'Group' is the selected layout from the left hand side.

Then go to 'Options' tab. Check 'Show Values' check box.

You can see a 'color' option button. Once you select that and click 'Format' button you will see a screen as shown by following figure. Here you can select different color for different party.

Note: This is an optional setting. If you are not setting colors here, system will automatically assign some colors.

Then go to 'Text' tab. You can see here Titles for the report, by default. If you need you can change like follow.

Now Click 'OK' button. You have followed all the essential steps and the result will be a bar chart. But this is not the final report with actual data.

Now you need to add crystal report viewer on the ASP.NET Webpage.

Let us see, how we can add the report viewer on the page, just look at these html tags. If you have done sample of earlier article, you can just add another button named 'Sample2' to asp.net page.

{codecitation class="brush: c#; gutter: true;" width="700px"} {/codecitation}

runat="server" AutoDataBind="true" />

{/codecitation}

Create a table in form object. Then add a html row and a column.

Then place the crystalReportViewer to the column as shown above html tag.

If we complie this application, it will give a complier error "CR doesn't exist". Therefore, you need to register crystal report namespace on the top of the page as shown below.

{codecitation class="brush: c#; gutter: true;" width="700px"}

{/codecitation}

Note: when you double click on toolbox in the crystalreportviewer Visual studio will do all registeration and etc.

Now write few lines to display report on the viewer.

{codecitation class="brush: c#; gutter: true;" width="700px"}

protected void Sample2_Click(object sender, EventArgs e)

{

// attached our report to viewer and set database login.

ReportDocument report = new ReportDocument();

report.Load(Server.MapPath("ChartSample2.rpt"));

report.SetDatabaseLogon("username", "pwd", @"server", "database");

rptviewer.ReportSource = report;

}

{/codecitation}

Then build the web application and run, you will get a report with chart. You can see total number of votes obtained by political party.

Conclusion:

This article is focused about creating chart reports using group layout option. I hope this article helped to you.

 
Sign Up to vote for this article
 
About Author
 
youngmurukan
Occupation-Not Provided
Company-Not Provided
Member Type-Senior
Location-Not Provided
Joined date-12 May 2009
Home Page-Not Provided
Blog Page-Not Provided
 
 
Other popularSectionarticles
Comments
There is no comments for this articles.
Leave a Reply
Title:
Display Name:
Email:
(not display in page for the security purphase)
Website:
Message:
Please refresh your screen using Ctrl+F5
If you can't read this number refresh your screen
Please input the anti-spam code that you can read in the image.
^ Scroll to Top