This tutorial will show you how to create a line graph with MS Chart in ASP.NET 3.5 and how to install the MS Chart extension. C#. Note: MS Chart is for use only with ASP.NET 3.5 and above.
In this tutorial, we will be looking at a new addition to the .NET Framework – MS Chart.
Please note that MS Chart will not work in ASP.NET 2.0 and below.

We will show you briefly how to install MS Chart, and how to utilize it to create a simple line graph. Once downloaded, you should have two files:

MSChart.exe and MSChart_VisualStudioAddOn.exe

Make sure Visual Studio.NET is closed, then run MSChart.exe first, and complete the quick install. Then run MSChart_VisualStudioAddOn.exe to install the VS Extension. Now open up Visual Studio and Create a new Web Site. If you want to add the Chart to your toolbox, you can right-click and Choose Items. Navigate to the install directory (Program Files > Microsoft Chart Controls) and choose the System.Web.DataVisualization.dll – click Ok. Once added, you can drag the DLLs and XML file from Windows Explorer.

Before we do anything, we need to add our references to the Web.config, because MS Chart is not yet fully integrated into .NET 3.5 and Visual Studio will not do this for you. Open up your Web.config and add the following two lines:
In system.web/httpHandlers, add this:

Then in system.webserver/handlers, add this:

Most of the code we write for the chart in the ASPX page will be for the way it looks.

When we move to our code-behind, we need to add the following reference:

To set the type of chart shown, let’s add the following on the Page_Load:

In order to display data as a chart, we need data ! For this example, we will use random data. The MS Chart plots its chart by looping through the data source and setting each value individually. Here, we will use a for loop to plot random integer values. To use your own data source, you will need to loop through it and assign the values (of type integer) to the chart in a similar way:

We then call this method on Page_Load, and ASP.NET will plot our graph:

If we wanted to add a second series, we can simply do that by adding to the tags like so:

Then set the type on Page_Load, and finally add to the method where we set our values:

Download Source Files