Archive for August, 2012

August 2, 2012

MSChart Controls in SharePoint / MOSS 2010

I had a chance to develop a Survey Webpart with MS Chart Control for SharePoint 2010.

Initially thought that getting the chart controls to work in SharePoint is similar to the way that we have to do in ASP.NET. But with SharePoint there are some stuffs we have to do it manually.

You can download the MS Chart from this link  and read more about the MS Chart controls from the link.

Once you open up a new fresh SharePoint 2010 project with a visual web part, then add a reference to the System.Web.DataVisualization.dll.

please add these entries in the web.conf file as below:

 <add name="ChartImageHandler" preCondition="integratedMode"  verb="GET,HEAD,POST" path="ChartImg.axd"
 type="System.Web.UI.DataVisualization.Charting.ChartHttpHandler,  System.Web.DataVisualization, Version=, Culture=neutral, PublicKeyToken=31bf3856ad364e35" />

 <add key="ChartImageHandler" value="storage=file;timeout=20;" />
 //<add key="ChartImageHandler" value="Storage=file;Timeout=20;Url=/_layouts/Images/MSChartImages/;" />
 //<add key="ChartImageHandler" value="Storage=memory;Timeout=20;" />

As well as please register the assembly in your user controls (.ascx file) as below.

<%@ Register Assembly="System.Web.DataVisualization, Version=, Culture=neutral, PublicKeyToken=31bf3856ad364e35"
 Namespace="System.Web.UI.DataVisualization.Charting" TagPrefix="asp" %>

After that add the Chart control to your page as mentioned below:

<asp:Chart ID="Chart1" runat="server" Width="550px" Height="350px">
 <asp:Series Name="Request" XValueMember="Column1"
 ChartType="Column" Palette="EarthTones"
 <asp:ChartArea Name="MainChartArea" Area3DStyle-
 <Area3DStyle Enable3D="true"></Area3DStyle>

From your code behind, retrieve the data what you need to be pushed into chart as a datatable and just set the datasource of the chart control as below.

Chart1.DataSource = yourDataTable;

read more about the MS Chart control in below link: