How to create a Chart / Graph using RDLC Report in C#
By FoxLearn 12/1/2024 8:15:12 AM 12.28K
In this article, we’ll walk through creating a chart in an RDLC report using Microsoft Report Viewer in a Windows Forms application. We'll use Entity Framework to fetch data from a database via a stored procedure and bind it to the RDLC report.
How to create a Chart / Graph using RDLC Report in C#?
Click New Project, then select Visual C# on the left, then Windows and then select Windows Forms Application. Name your project "RDLCChart" and then click OK
Use the ADO.NET Entity Data Model wizard to create an Entity Framework model, connect to your database, and include the GetOrdersExport
stored procedure, which retrieves order data.
Add an RDLC file to your project by right-clicking the project, select Add > New Item, and choose Report.
Open the RDLC file in the designer, then drag a Chart control from the toolbox onto the report.
Select a chart type, then bind the data fields to the category groups (X-axis) and values (Y-axis).
Drag and drop the ReportViewer control from the Visual Studio toolbox onto your form designer, and set its DataSource to the desired report.
You need to install Microsoft.Reporting.WinForms
in your project.
Here is the complete code for Form1.cs
using System; using System.Collections.Generic; using System.ComponentModel; using System.Data; using System.Drawing; using System.Linq; using System.Text; using System.Threading.Tasks; using System.Windows.Forms; namespace RDLCChart { public partial class Form1 : Form { public Form1() { InitializeComponent(); } private void Form1_Load(object sender, EventArgs e) { using (NorthwindEntities db = new NorthwindEntities()) { // Fetch data from the stored procedure GetOrdersExport_ResultBindingSource.DataSource = db.GetOrdersExport().ToList(); // Refresh the Report Viewer this.reportViewer1.RefreshReport(); } } } }
In this example, I'm using the Northwind database with the GetOrdersExport
procedure.
VIDEO TUTORIAL
- How to Create Report Viewer using Stored Procedure in C#
- How to Create QR Code in RDLC Report in C#
- How to Print RDLC Report without Report Viewer in C#
- How to Display an Image in Report Viewer using C#
- Windows Forms: Print Orders/Receipt using Report Viewer in C#
- Windows Forms: Print Receipt using Report Viewer in C#