locked
How To Create Graph In ASPX Page Load RRS feed

  • Question

  • User2033107836 posted

    Hello

    This I want to make like this graph and bind data from database

    How To Create Graph and show like this above data will fetch from database table

    Tuesday, March 21, 2017 2:54 PM

Answers

  • User-707554951 posted

    Hi asp.ambur,

    As far as I know, built-in chart control exist in asp.net 4.0.

    So, I suggest you could use .net 4.0 rather than .net 2.0;

    Then you could use the following code:

    <asp:Chart ID="Chart1" runat="server">
                <Series >
                    <asp:Series Name="Series1" ChartType="Line" XValueMember="X" YValueMembers="Y" ></asp:Series>
                </Series>
                <ChartAreas>
                    <asp:ChartArea Name="ChartArea1" >
                        <AxisY Interval="1" Maximum="4">
                        </AxisY>
                        <AxisX Interval="10" Maximum="30" Minimum="0">
                        </AxisX>
                    </asp:ChartArea>
                </ChartAreas>
            </asp:Chart>
    

    CodeBehind:

      DataTable dt = new DataTable();
                dt.Columns.AddRange(new DataColumn[] { new DataColumn("X", typeof(float)), new DataColumn("Y", typeof(float)) });
                dt.Rows.Add(5.0, 1.5);
                dt.Rows.Add(10.0, 4.0);
                dt.Rows.Add(10.5, 3.5);
                dt.Rows.Add(20.0, 0.5);
                dt.Rows.Add(20.5, 1.5);
                dt.Rows.Add(30.0, 4.5);
                Chart1.DataSource = dt;
                Chart1.DataBind();
             

    Output screenshot as below:

      DataTable dt = new DataTable();
                dt.Columns.AddRange(new DataColumn[] { new DataColumn("X", typeof(float)), new DataColumn("Y", typeof(float)) });
                dt.Rows.Add(5.0, 1.5);
                dt.Rows.Add(10.0, 4.0);
                dt.Rows.Add(10.5, 3.5);
                dt.Rows.Add(20.0, 0.5);
                dt.Rows.Add(20.5, 1.5);
                dt.Rows.Add(30.0, 4.5);
                Chart1.DataSource = dt;
                Chart1.DataBind();
             
    

    Output screenshot as below:

    Best regards

    Cathy
     

    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Wednesday, March 22, 2017 9:08 AM

All replies