--> if you want to create chart in asp.net from database data that time do following
--> Here table name tbl and field(Id,name,age)
-->copy following code in .aspx page
------------------------------------------------------------------------------------------------
--> Next , Copy the following code in your code behind file
--> add namespace
------------------------------------------------------------------------------------------------
--> create object above pageload event
------------------------------------------------------------------------------------------------
--> Following code in your page load event
------------------------------------------------------------------------------------------------
-->Create one method for get chart data
------------------------------------------------------------------------------------------------
--> Here table name tbl and field(Id,name,age)
-->copy following code in .aspx page
------------------------------------------------------------------------------------------------
<div>
Chart control in asp.net<br />
<br />
<asp:chart id="Chart5" runat="server" width="1000px" height="335px">
<series>
<asp:Series Name="age" XValueMember="name"
YValueMembers="age"
>
</asp:Series>
<asp:Series Name="id" XValueMember="name" YValueMembers="id"></asp:Series>
</series>
<chartareas>
<asp:ChartArea Name="Age">
</asp:ChartArea>
</chartareas>
<legends>
<asp:Legend Name="name" Title=" chart : Display age for particaular
student"></asp:Legend>
</legends>
</asp:chart>
</div>
--> Next , Copy the following code in your code behind file
--> add namespace
------------------------------------------------------------------------------------------------
using System.Data.SqlClient;
using System.Data;
--> create object above pageload event
------------------------------------------------------------------------------------------------
SqlConnection cn;
SqlCommand cmd;
SqlDataAdapter da;
DataSet ds;
--> Following code in your page load event
------------------------------------------------------------------------------------------------
cn = new SqlConnection(@"Data Source=YOUR CONNECTION STRING;Initial
Catalog=student;Integrated Security=True");
if (!IsPostBack)
{
disp();
}
-->Create one method for get chart data
------------------------------------------------------------------------------------------------
public void disp()
{
cmd =
new SqlCommand("select * from tbl", cn);
da = new SqlDataAdapter(cmd);
ds = new DataSet();
da.Fill(ds);
Chart5.DataSource = ds;// fill data in chart
Chart5.DataBind();
}
No comments:
Post a Comment