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:

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

</pre>
<appSettings>
 <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;" />
 </appSettings>

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

</pre>
<%@ Register Assembly="System.Web.DataVisualization, Version=3.5.0.0, 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">
 <Series>
 <asp:Series Name="Request" XValueMember="Column1"
 YValueMembers="Column2"
 ChartType="Column" Palette="EarthTones"
 ChartArea="MainChartArea">
 </asp:Series>
 </Series>
 <ChartAreas>
 <asp:ChartArea Name="MainChartArea" Area3DStyle-
 Enable3D="true">
 <Area3DStyle Enable3D="true"></Area3DStyle>
 </asp:ChartArea>
 </ChartAreas>
 </asp:Chart>

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.

</pre>
Chart1.DataSource = yourDataTable;
 Chart1.DataBind();

read more about the MS Chart control in below link:

http://www.dotnetspark.com/

Advertisements