locked
asp.net chart control does not display RRS feed

  • Question

  • User-390872747 posted

    Hi, I have added a asp.net chart control to my C# web application.

    When I run the application, the chart does not display. It just shows a little black square with a white cross mark in it.

    I am not sure if I am missing something or what is causing this. Can you please help ? Thanks

    Here is the code I am using..

        <asp:Chart ID="Chart1" runat="server" style="z-index: 1; left: 163px; top: 800px; " Height="700px" Width="1800px">

            <Series>

                <asp:Series Name="Series1">

                </asp:Series>

            </Series>

            <ChartAreas>

                <asp:ChartArea Name="ChartArea1">

                    <AxisY Title="FailCount" TitleFont="Microsoft Sans Serif, 12pt">

                    </AxisY>

                    <AxisX Title="A.B.C" TitleFont="Microsoft Sans Serif, 12pt">

                    </AxisX>

                    <Area3DStyle Enable3D="False" />

                </asp:ChartArea>

            </ChartAreas>

            <Titles>

                <asp:Title Font="Microsoft Sans Serif, 12pt" Name="Title1">

                </asp:Title>

            </Titles>

        </asp:Chart>

     

     

                    foreach (DataRow dr in mydata.Rows)

                    {

                        string xcol = dr["TestName1"].ToString();

                        string ycol = dr”FailCount"].ToString();

                        int index = this.Chart1.Series["Series1"].Points.AddXY(xcol, ycol);

                    }

     

                    Chart1.ChartAreas[0].AxisX.Interval = 1;

                    Chart1.Titles[0].Text = "My Chart "

    Sunday, May 8, 2016 4:15 AM

Answers

  • User2103319870 posted

    When I run the application, the chart does not display. It just shows a little black square with a white cross mark in it.

    Try loading the data to chart like given below

     <asp:Chart ID="Chart2" runat="server" Style="z-index: 1; left: 163px; top: 800px; ">
                    <Series>
                        <asp:Series Name="Series1">
                        </asp:Series>
                    </Series>
                    <ChartAreas>
                        <asp:ChartArea Name="ChartArea1">
                            <AxisY Title="FailCount" TitleFont="Microsoft Sans Serif, 12pt">
                            </AxisY>
                            <AxisX Title="A.B.C" TitleFont="Microsoft Sans Serif, 12pt">
                            </AxisX>
                            <Area3DStyle Enable3D="False" />
                        </asp:ChartArea>
                    </ChartAreas>
                    <Titles>
                        <asp:Title Font="Microsoft Sans Serif, 12pt" Name="Title1">
                        </asp:Title>
                    </Titles>
                </asp:Chart>

    C#:

     protected void Page_Load(object sender, EventArgs e)
            {
                //Some Dummy data
                DataTable table = new DataTable();
                table.Columns.Add("TestName1", typeof(string));
                table.Columns.Add("FailCount", typeof(string));
    
                // Here we add five DataRows.
                table.Rows.Add("Name1", "201");
                table.Rows.Add("Name2", "23");
                table.Rows.Add("Name3", "45");
                table.Rows.Add("Name4", "67");
    
                List<string> xvals = new List<string>();
                List<decimal> yvals = new List<decimal>();
                foreach (DataRow dr in table.Rows)
                {
                    xvals.Add(dr["TestName1"].ToString());
                    yvals.Add(Convert.ToDecimal(dr["FailCount"].ToString()));
    
                }
                Chart2.Series["Series1"].XValueType = ChartValueType.String;
                Chart2.Series["Series1"].YValueType = ChartValueType.Auto;
                Chart2.Series["Series1"].Points.DataBindXY(xvals.ToArray(), yvals.ToArray());
                Chart2.DataBind();
            }

    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Sunday, May 8, 2016 6:20 PM

All replies

  • User2103319870 posted

    When I run the application, the chart does not display. It just shows a little black square with a white cross mark in it.

    Try loading the data to chart like given below

     <asp:Chart ID="Chart2" runat="server" Style="z-index: 1; left: 163px; top: 800px; ">
                    <Series>
                        <asp:Series Name="Series1">
                        </asp:Series>
                    </Series>
                    <ChartAreas>
                        <asp:ChartArea Name="ChartArea1">
                            <AxisY Title="FailCount" TitleFont="Microsoft Sans Serif, 12pt">
                            </AxisY>
                            <AxisX Title="A.B.C" TitleFont="Microsoft Sans Serif, 12pt">
                            </AxisX>
                            <Area3DStyle Enable3D="False" />
                        </asp:ChartArea>
                    </ChartAreas>
                    <Titles>
                        <asp:Title Font="Microsoft Sans Serif, 12pt" Name="Title1">
                        </asp:Title>
                    </Titles>
                </asp:Chart>

    C#:

     protected void Page_Load(object sender, EventArgs e)
            {
                //Some Dummy data
                DataTable table = new DataTable();
                table.Columns.Add("TestName1", typeof(string));
                table.Columns.Add("FailCount", typeof(string));
    
                // Here we add five DataRows.
                table.Rows.Add("Name1", "201");
                table.Rows.Add("Name2", "23");
                table.Rows.Add("Name3", "45");
                table.Rows.Add("Name4", "67");
    
                List<string> xvals = new List<string>();
                List<decimal> yvals = new List<decimal>();
                foreach (DataRow dr in table.Rows)
                {
                    xvals.Add(dr["TestName1"].ToString());
                    yvals.Add(Convert.ToDecimal(dr["FailCount"].ToString()));
    
                }
                Chart2.Series["Series1"].XValueType = ChartValueType.String;
                Chart2.Series["Series1"].YValueType = ChartValueType.Auto;
                Chart2.Series["Series1"].Points.DataBindXY(xvals.ToArray(), yvals.ToArray());
                Chart2.DataBind();
            }

    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Sunday, May 8, 2016 6:20 PM
  • User-390872747 posted

    I used your code. Unfortunately, I still have the same result. I am just do not what is wrong. The code compiles & runs without giving any errors.

    Is there a way to some how debug such an issue,, get some details on why the chart does not show up ?

    Thanks

    Monday, May 9, 2016 3:16 AM
  • User36583972 posted

    Hi diana4,

    I have tested the code which a2h give. It is ok, I found the chart show data in the page.

    I think you can refer the following tutorials and check your application again.

    1: ASP.NET 4.0 Chart Control:

    http://www.codeproject.com/Articles/235117/ASP-NET-Chart-Control

    2: Create ASP.Net Chart Control from Database using C# and VB.Net Example:

    http://www.aspsnippets.com/Articles/Create-ASPNet-Chart-Control-from-Database-using-C-and-VBNet-Example.aspx

    3: Populate ASP.Net 4.0 Chart Control Pie Chart from SQL Server Database:

    http://www.aspsnippets.com/Articles/Populate-ASPNet-40-Chart-Control-Pie-Chart-from-SQL-Server-Database.aspx

    Best Regards,

    Yohann Lu

    Tuesday, May 10, 2016 8:23 AM