In this article I will explain a short step by step tutorial with example on how to add charts to the ASP.Net ReportViewer control. I will explain with an example to display a Pie Chart in the RDLC Report ReportViewer in ASP.Net using C# and VB.Net.
I will be making use of a Typed DataSet for populating the Chart data in the RDLC Report.
 
 
 
Database
Here I am making use of Microsoft’s Northwind Database. You can download it from here
 
 
1. Add Typed DataSet to the ASP.Net Website
Since I am using disconnected RDLC Reports we will make use of Typed DataSet to populate the RDLC Reports with data from database.
Adding Charts to ASP.Net ReportViewer Control: Display Pie Chart in RDLC Report in ASP.Net
 
 
2. Adding DataTable to the Typed DataSet
Our next step would be to add a DataTable to the Type DataSet.
Adding Charts to ASP.Net ReportViewer Control: Display Pie Chart in RDLC Report in ASP.Net
 
 
3. Adding Columns or fields to DataTable
In the DataTable we need to specify the column names that we want to display in the RDLC Report.
Note: The Column Names of the DataTable must exactly match with the actual column or alias names in the query.
 
Adding Charts to ASP.Net ReportViewer Control: Display Pie Chart in RDLC Report in ASP.Net
 
By default all the columns are of String Data Type but you can also change the data type as per your need using the Properties window.
Adding Charts to ASP.Net ReportViewer Control: Display Pie Chart in RDLC Report in ASP.Net
 
 
4. Adding the RDLC Report
Using the Add New Item option in Visual Studio you need to add new RDLC Report.
Adding Charts to ASP.Net ReportViewer Control: Display Pie Chart in RDLC Report in ASP.Net
 
 
5. Add Chart to the Report
The above action will create a Blank Report. You will need to right click and Click Insert and then Chart as shown below.
Adding Charts to ASP.Net ReportViewer Control: Display Pie Chart in RDLC Report in ASP.Net
 
 
6. Choose the Chart Type
Next you need to choose the type of Chart you want to use in your Report from the Select Chart Type dialog.
Adding Charts to ASP.Net ReportViewer Control: Display Pie Chart in RDLC Report in ASP.Net
 
 
7. Choose the DataSet
Now we need to choose the DataSet that will act as the DataSource for the RDLC Report. Thus we need to select the Custom DataSet that we have created earlier.
Adding Charts to ASP.Net ReportViewer Control: Display Pie Chart in RDLC Report in ASP.Net
 
 
8. Set the Data Fields
Once the DataSet is chosen, the Pie Chart will be displayed in the RDLC Report. Now we need to
1. Right Click on the Pie Chart.
2. Click the Data Fields section and select the Field for the Pie Chart’s Data Field by clicking on the small icon as shown below. I have chosen OrderId as Data Field.
Note: Data Field is a column that will determine the share or size of each Pie in a Pie chart.
3. Repeat the same procedure for the Category fields. I have chosen, Ship City as the Category field.
Adding Charts to ASP.Net ReportViewer Control: Display Pie Chart in RDLC Report in ASP.Net
 
You will notice that an aggregate SUM function is automatically applied to the OrderId.
Adding Charts to ASP.Net ReportViewer Control: Display Pie Chart in RDLC Report in ASP.Net  
 
But since I don’t want to SUM OrderId, I will have to modify it to make use of COUNT aggregate function by right clicking the Data Field section and then clicking Series Properties.
Adding Charts to ASP.Net ReportViewer Control: Display Pie Chart in RDLC Report in ASP.Net
 
In the Series Properties Window, you can easily change the Formula you want to use. Since I need to display Order Distribution in various Cities, I have used COUNT aggregate function.
Adding Charts to ASP.Net ReportViewer Control: Display Pie Chart in RDLC Report in ASP.Net
 
 
9. Displaying Labels on Chart and Changing Title
Our next job is to display the values of each Pie in Pie Chart. Thus you need to right click on the Chart and then click Show Data Labels.
Adding Charts to ASP.Net ReportViewer Control: Display Pie Chart in RDLC Report in ASP.Net
 
Then you need to double click on Chart Title and type in the appropriate Title for the Chart.
Adding Charts to ASP.Net ReportViewer Control: Display Pie Chart in RDLC Report in ASP.Net
 
 
10. Adding Report Viewer to the page
In order to display the Report we will need to add ReportViewer control to the page from the Toolbox. The ReportViewer controls requires ScriptManager on the page.
Adding Charts to ASP.Net ReportViewer Control: Display Pie Chart in RDLC Report in ASP.Net
 
 
Once you add the ReportViewer control to the page, your page must look as below.
<%@ Register Assembly="Microsoft.ReportViewer.WebForms, Version=10.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a"
    Namespace="Microsoft.Reporting.WebForms" TagPrefix="rsweb" %>
 
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
    <title></title>
</head>
<body>
    <form id="form1" runat="server">
    <asp:ScriptManager ID="ScriptManager1" runat="server">
    </asp:ScriptManager>
    <rsweb:ReportViewer ID="ReportViewer1" runat="server" Width="600">
    </rsweb:ReportViewer>
    </form>
</body>
</html>
 
 
11. Populating the RDLC Report from Database
Below is the code to populate the RDLC Report from database. The first statement notifies the ReportViewer control that the Report is of type Local Report.
Then the path of the Report is supplied to the ReportViewer, after that the Customers DataSet is populated with records from the Customers Table and is set as ReportSource to the Report.
C#
Namespaces
using System.Data;
using System.Configuration;
using System.Data.SqlClient;
using Microsoft.Reporting.WebForms;
 
protected void Page_Load(object sender, EventArgs e)
{
    if (!IsPostBack)
    {
        ReportViewer1.ProcessingMode = ProcessingMode.Local;
        ReportViewer1.LocalReport.ReportPath = Server.MapPath("~/Report.rdlc");
        CustomDataSet dsCustomers = GetData();
        ReportDataSource datasource = new ReportDataSource("dsOrders", dsCustomers.Tables[0]);
        ReportViewer1.LocalReport.DataSources.Clear();
        ReportViewer1.LocalReport.DataSources.Add(datasource);
    }
}
 
private CustomDataSet GetData()
{
    string query = "SELECT ShipCity, OrderId FROM Orders WHERE ShipCountry = 'France'";
    string conString = ConfigurationManager.ConnectionStrings["constr"].ConnectionString;
    SqlCommand cmd = new SqlCommand(query);
    using (SqlConnection con = new SqlConnection(conString))
    {
        using (SqlDataAdapter sda = new SqlDataAdapter())
        {
            cmd.Connection = con;
 
            sda.SelectCommand = cmd;
            using (CustomDataSet dsCustomers = new CustomDataSet())
            {
                sda.Fill(dsCustomers, "DataTable1");
                return dsCustomers;
            }
        }
    }
}
 
VB.Net
 
Namespaces
Imports System.Data
Imports System.Configuration
Imports System.Data.SqlClient
Imports Microsoft.Reporting.WebForms
 
Protected Sub Page_Load(sender As Object, e As EventArgs) Handles Me.Load
    If Not IsPostBack Then
        ReportViewer1.ProcessingMode = ProcessingMode.Local
        ReportViewer1.LocalReport.ReportPath = Server.MapPath("~/Report.rdlc")
        Dim dsCustomers As CustomDataSet = GetData()
        Dim datasource As New ReportDataSource("dsOrders", dsCustomers.Tables(0))
        ReportViewer1.LocalReport.DataSources.Clear()
        ReportViewer1.LocalReport.DataSources.Add(datasource)
    End If
End Sub
 
Private Function GetData() As CustomDataSet
    Dim query As String = "SELECT ShipCity, OrderId FROM Orders WHERE ShipCountry = 'France'"
    Dim conString As String = ConfigurationManager.ConnectionStrings("constr").ConnectionString
    Dim cmd As New SqlCommand(query)
    Using con As New SqlConnection(conString)
        Using sda As New SqlDataAdapter()
            cmd.Connection = con
 
            sda.SelectCommand = cmd
            Using dsCustomers As New CustomDataSet()
                sda.Fill(dsCustomers, "DataTable1")
                Return dsCustomers
            End Using
        End Using
    End Using
End Function
 
Adding Charts to ASP.Net ReportViewer Control: Display Pie Chart in RDLC Report in ASP.Net
 
 
Demo
 
 
Downloads