How to create graph in asp.net:

How to create graph in asp.net:




As we know that the .net provides Graph controls for programming and data representation in graphically .today we simply learn how to use these graph controls in asp.net and how to represent data in Graph.

 we describe some steps for using Graph Controls:

Step 1: create a Table in data base



      CREATE TABLE [dbo].[emp](
      [emp_id] [int] IDENTITY(1,1) NOT NULL,
      [emp_name] [nvarchar](50) NULL,
      [salary] [int] NULL
) ON [PRIMARY]

And then fill data in to table:


Now go to .net EID for using Graph.

Step 2: get the Graph Control in to aspx page as like.

Code of aspx page :

<%@ Page Language="C#" AutoEventWireup="true" CodeFile="Default2.aspx.cs" Inherits="Default2" %>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
    <title></title>
</head>
<body>
    <form id="form1" runat="server">
    <div>
    <asp:Chart ID="Chart2" runat="server" Width="375px">
                                <Titles>
                                    <asp:Title ShadowOffset="1" Name="Items" Font="Microsoft Sans Serif, 12pt"
                                        Text="Students List " />
                                </Titles>
                                <Series>
                                    <asp:Series Name="Series1" ChartArea="ChartArea1" YValuesPerPoint="10" ChartType="Column">
                                    </asp:Series>
                                </Series>
                                <ChartAreas>
                                    <asp:ChartArea Name="ChartArea1" BorderWidth="0">
                                        <Area3DStyle Enable3D="True" Rotation="15" />
                                    </asp:ChartArea>
                                </ChartAreas>
                            </asp:Chart>
    </div>
    </form>
</body>
</html>



Code in .aspx.cs page :

private void FillEMP()
    {
        DataSet dsEmp = new DataSet();
        dsEmp = objComm.RunSQLQuery("select salary,emp_name as NAME from Test.dbo.emp");
        Chart6.DataSource = dsEmp;
        Chart6.ChartAreas["ChartArea1"].AxisX.Title = "NAME";
        Chart6.ChartAreas["ChartArea1"].AxisY.Title = "SALARY";
        Chart6.Series["Series1"].XValueMember = "NAME";

        Chart6.Series["Series1"].YValueMembers = "salary";
        Chart6.Series[0].ToolTip = "SALARY: #VAL";
        Chart6.Series["Series1"].LegendToolTip = "";
        Chart6.Series["Series1"].LabelToolTip = "#VAL";
        Chart6.Series["Series1"].IsValueShownAsLabel = true;
        Chart6.DataBind();
    }

   
        Chart5.Series["Series1"].IsValueShownAsLabel = true;
        Chart5.DataBind();
    }

Called this function on page load ,you call this anywhere as you like .


The result is :


Checkboxlist related post :


Comments

Popular posts from this blog