ASPX Page:
<asp:Chart ID="Chart1" runat="server" Width="500">
<series>
<asp:Series
Name="Population"
XValueMember="Year"
YValueMembers="Population"
IsVisibleInLegend="true">
</asp:Series>
</series>
<chartareas>
<asp:ChartArea
Name="ChartArea1"
Area3DStyle-Enable3D="true">
<AxisX LineColor="DarkGreen">
<MajorGrid LineColor="LightGray" />
</AxisX>
<AxisY LineColor="DarkGreen">
<MajorGrid LineColor="LightGray" />
</AxisY>
</asp:ChartArea>
</chartareas>
<Legends>
<asp:Legend></asp:Legend>
</Legends>
</asp:Chart>
Code Behind:
try
{
var table = new DataTable();
table.Columns.Add("Year", typeof(int));
table.Columns.Add("Population", typeof(long));
table.Columns.Add("Lbl");
using (SPSite site = new SPSite(YourSiteUrl))
{
using (SPWeb web = site.OpenWeb())
{
SPList _bugetlist = web.Lists["YearTotal"];
foreach (SPListItem _item1 in _bugetlist.Items)
{
var row = table.NewRow();
row["Year"] = Convert.ToInt16(_item1["Year"]);
row["Population"] = Convert.ToInt16(_item1["Population"]);
table.Rows.Add(row);
}
}
}
Chart1.ChartAreas["ChartArea1"].AxisY.Title = "Population";
Chart1.ChartAreas["ChartArea1"].AxisX.Title = "Years";
Chart1.DataSource = table;
Chart1.DataBind();
In web.config
<appSettings>
<add key="ChartImageHandler" value="storage=file;timeout=20;dir=c:\TDG\;" />
</appSettings>
<handlers>
<remove name="ChartImageHandler" />
<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" />
<add name="ReportViewerWebControlHandler" preCondition="integratedMode" verb="*" path="Reserved.ReportViewerWebControl.axd" type="Microsoft.Reporting.WebForms.HttpHandler, Microsoft.ReportViewer.WebForms, Version=10.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a" />
</handlers>
<httpHandlers>
<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" />
<add verb="*" path="Reserved.ReportViewerWebControl.axd" type="Microsoft.Reporting.WebForms.HttpHandler, Microsoft.ReportViewer.WebForms, Version=9.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a" />