Click here to Skip to main content
15,886,110 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
C#
public partial class chart3 : System.Web.UI.Page
{
    SqlConnection con;
    SqlCommand cmd;
    SqlDataAdapter da;
    DataTable dt;
    protected void Page_Load(object sender, EventArgs e)
    {
        con = new SqlConnection(@"connectionString");
        cmd = new SqlCommand("Select * from GraphChart",con);
        da = new SqlDataAdapter(cmd);
        dt = new DataTable();
        da.Fill(dt);
        Chart1.DataSource = dt;
        Chart1.DataBind();
    }
}


Source:

C#
<div>
 <asp:Chart ID="Chart1" runat="server"  CssClass="auto-style1" Width="423px">
            <Series>
                <asp:Series Name="Series1" XValueMember="Name"></asp:Series>
                <asp:Series Name="Series2" YValueMembers="Age"></asp:Series>

            </Series>
            <ChartAreas>
                <asp:ChartArea Name="ChartArea1"></asp:ChartArea>
            </ChartAreas>
            <Legends>
                <asp:Legend Title="Employee Data"></asp:Legend>
            </Legends> 
        </asp:Chart>
</div>
Posted
Comments
[no name] 23-Sep-14 4:52am    
try to figure it , be a programmer not a coder you can get help with google to figure out the little pieces of the solution

1 solution

The code give below is working.
Thank you.

C#
public partial class chart3 : System.Web.UI.Page
{
    SqlConnection con;
    SqlCommand cmd;
    SqlDataAdapter da;
    DataSet ds;
    protected void Page_Load(object sender, EventArgs e)
    {
        con = new SqlConnection(@"connectionString");
        cmd = new SqlCommand("Select * from GraphChart",con);
        da = new SqlDataAdapter(cmd);
        ds = new DataSet();
        da.Fill(ds);
        DataView source = new DataView(ds.Tables[0]);
        Chart1.DataSource = source; 
        Chart1.Series[0].XValueMember = "Name";
        Chart1.Series[0].YValueMembers = "Age";
        Chart1.DataBind();
    }
}
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900