This tutorial will show you how to successfully
install and begin using Microsoft Chart Controls in Visual Studio.NET
2008 and .NET 3.5.
Installing Microsoft Chart Controls for .NET 3.5
This tutorial will show you how to successfully
install and begin using Microsoft Chart Controls in Visual Studio.NET
2008 and .NET 3.5
Microsoft Chart Controls is a new implementation to the .NET
Framework which allows us to easily render data in graphical form.
Previously, we had to use third-party plug-ins to implement graphs and
charts into our ASP.NET Web Applications, but now, Microsoft have
introduced a native method. MSChart is not compatible with .NET 1.1 nor
2.0, and can only be used with .NET 3.5 and above.
To get started with MS Chart, you can download it free directly from Microsoft at the following web address:
www.microsoft.com/downloads/details.aspx?FamilyID=130...lang=en
If you'll be using Visual Studio also, you can download the free add-on directly from the following address:
www.microsoft.com/downloads/details.aspx?familyid=1D6...lang=en
This add-on will allow us to add the MSChart control to our toolbox, and also provide the intellisense for MSChart.
Another useful link is for Samples of the Chart Controls:
http://code.msdn.microsoft.com/mschart
Once you have downloaded the files above, install the first one
(MSChart.exe) and then install the VS add-on second. This is because
the add-on requires MSChart to be installed. Installations should be
completed whilst Visual Studio.NET is not running.
Once installations are complete, you can start up Visual Studio and open or create a new project.
To add MSChart to the toolbox, right-click on any blank area and select
Add Tab. Name it MS Chart, or something similar. Then right-click
inside the new tab, and select Choose Items. After a few seconds, you
will be prompted with the Choose Toolbox Items dialog box. Hit the
Browse button and navigate to Program Files\Microsoft Chart
Controls\Assemblies. We want to select the DataVisualization DLLs -
there is one for Web Forms, and one for Windows Forms.
Once these have been added, you should see there is a Pointer and a
Chart option, that was added. Now we are all set to start using Chart
Controls from Microsoft.
However, before we can implement Charts in our applications, we need
to prepare them. Because .NET 3.5 does not natively support MSChart (it
was an add-on), we need to add two references to our Web.config file.
The first, we will add inside the
<system.web><httpHandlers></system.web></httpHandlers>
tags. Locate these tags and add the following reference:
|
<add path="ChartImg.axd" verb="GET,HEAD"
type="System.Web.UI.DataVisualization.Charting.ChartHttpHandler,
System.Web.DataVisualization, Version=3.5.0.0, Culture=neutral,
PublicKeyToken=31bf3856ad364e35" validate="false"/> |
Server Intellect
assists companies of all sizes with their hosting needs by offering
fully configured server solutions coupled with proactive server
management services. Server Intellect specializes in providing complete internet-ready server solutions backed by their expert 24/365 proactive support team.
The second reference we need to add to the Web.config is within the
<system.webserver><handlers></system.webserver></handlers>
tags. Locate this and add the following:
|
<add name="ChartImageHandler" preCondition="integratedMode"
verb="GET,HEAD" path="ChartImg.axd"
type="System.Web.UI.DataVisualization.Charting.ChartHttpHandler,
System.Web.DataVisualization, Version=3.5.0.0, Culture=neutral,
PublicKeyToken=31bf3856ad364e35"/> |
When adding a Chart Control to an ASPX page by dragging from the
toolbox, you should notice the following assembly reference is added to
the top of the page:
|
<%@ Register Assembly="System.Web.DataVisualization,
Version=3.5.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35"
Namespace="System.Web.UI.DataVisualization.Charting" TagPrefix="asp"
%> |
Finally, when referencing the Chart Controls in the codebehind, you should add the following using directive:
C#.NET:
|
using System.Web.UI.DataVisualization.Charting;
|
VB.NET:
|
Imports System.Web.UI.DataVisualization.Charting
|
Now you have the basis to implement MSChart into your Web
Applications. Explore the easy way to add beautiful graphics to your
data output.
|