Problem to Chart

Hi,
The chart in the beginning part of page, is not being shown properly with the data from the table
http://my-friend.co/HouseList4/Default.aspx?userid=mc1

what can be the reason of problem? Here are the codes to create the chart

                string query = "select [house_sch].dbo.getletter(ROW_NUMBER() OVER (ORDER BY house_id)) house_name, price from [house_sch].[dbo].[house_tab] order by house_id";
                DataTable dt = GetData(query);

                string[] x = new string[dt.Rows.Count];
                decimal[] y = new decimal[dt.Rows.Count];
                for (int i = 0; i < dt.Rows.Count; i++)
                {
                    x[i] = dt.Rows[i][0].ToString();
                    y[i] = Convert.ToInt32(dt.Rows[i][1]);
                }
                BarChart1.Series.Add(new AjaxControlToolkit.BarChartSeries { Data = y });
                BarChart1.CategoriesAxis = string.Join(",", x);
                BarChart1.ChartTitle = "房价的起伏与升跌";

Open in new window

LVL 11
HuaMin ChenProblem resolverAsked:
Who is Participating?
 
Ryan ChongCommented:
I didn't adjust much:

Front end:

<asp:ScriptManager ID="ScriptManager1" runat="server">
        </asp:ScriptManager>
        <ajaxToolkit:BarChart ID="BarChart1" runat="server" Height="425px">
        </ajaxToolkit:BarChart>

Open in new window


code behind: (for testing purposes, I use my own datatable with test data)

protected void Page_Load(object sender, EventArgs e)
        {
            //string query = "select [house_sch].dbo.getletter(ROW_NUMBER() OVER (ORDER BY house_id)) house_name, price from [house_sch].[dbo].[house_tab] order by house_id";
            //DataTable dt = GetData(query);
            
            SqlConnection conn = new SqlConnection("Data Source=machine;Initial Catalog=myDB;Persist Security Info=True;User ID=userid;Password=password");
            conn.Open();

            SqlCommand cmd = new SqlCommand("select Field1, Field2 from YourTable", conn);
            SqlDataAdapter da = new SqlDataAdapter(cmd);
            DataTable dt = new DataTable();
            da.Fill(dt);

            string[] x = new string[dt.Rows.Count];
            decimal[] y = new decimal[dt.Rows.Count];
            for (int i = 0; i < dt.Rows.Count; i++)
            {
                x[i] = dt.Rows[i][0].ToString();
                y[i] = Convert.ToInt32(dt.Rows[i][1]);
            }
            BarChart1.Series.Add(new AjaxControlToolkit.BarChartSeries { Data = y });
            BarChart1.CategoriesAxis = string.Join(",", x);
            BarChart1.ChartTitle = "房价的起伏与升跌";

        }

Open in new window

0
 
Ryan ChongCommented:
well, I just done a similar page with scripts above and it seems worked to me (just a bit off for the positioning)

snap.jpg
what error have you encountered?
0
 
HuaMin ChenProblem resolverAuthor Commented:
Thanks a lot. What did you adjust to show the chart?

There is no error to the chart.
0
Ultimate Tool Kit for Technology Solution Provider

Broken down into practical pointers and step-by-step instructions, the IT Service Excellence Tool Kit delivers expert advice for technology solution providers. Get your free copy now.

 
HuaMin ChenProblem resolverAuthor Commented:
Appreciated. What can be reason that chart is not shown properly, to my case?
0
 
Ryan ChongCommented:
What can be reason that chart is not shown properly, to my case?

try to put some break points in your codes and then check and make sure your DataTable dt returns something?
0
 
HuaMin ChenProblem resolverAuthor Commented:
Yes, query is returning records below
21d.png
0
 
Ryan ChongCommented:
Yes, query is returning records

ok, try make sure:

you got ScriptManager in front end?

<asp:ScriptManager ID="ScriptManager1" runat="server">
        </asp:ScriptManager>

Open in new window


and make break point(s) in code behind, probably at line:

string[] x = new string[dt.Rows.Count];

Open in new window


and see if you can find out the abnormally?
0
 
HuaMin ChenProblem resolverAuthor Commented:
Yes, details are fine. There was no problem at all, before this, and I do not know why problem arose, without applying any change/adjustment.
0
 
Ryan ChongCommented:
ok, no idea too.

try to re-build your solution and see if there's any errors

also use simple method as shown in ID: 42482247, perhaps on a new page file and see if you can generate that chart successfully.
0
 
HuaMin ChenProblem resolverAuthor Commented:
Sorry to that I want to see if there is any clue now, to current issue.
0
 
Ryan ChongCommented:
think need apply some debugging techniques (like putting the break points, etc) in order to find out the exact issues from your codes.

but unfortunately we can't remotely login to your System  for debugging, so we only can provide guidance how we usually solve similar issues.
0
 
HuaMin ChenProblem resolverAuthor Commented:
I am checking the deployed Web page and how to detect the reason of current problem?
0
 
Ryan ChongCommented:
I am checking the deployed Web page and how to detect the reason of current problem?
another way will be write the log to a file and debug from it.

have you heard about log4net library before?

you can easily integrate it to your VS project via Nuget:

log4net 2.0.8
https://www.nuget.org/packages/log4net/
0
 
HuaMin ChenProblem resolverAuthor Commented:
Hi Ryan,
I did also show you the query last time. Do you think which column value (of query) can give any clue of the issue?
0
 
Ryan ChongCommented:
Do you think which column value (of query) can give any clue of the issue?
if your query did return records then your chart should show the results...

i would suggest to use the techniques mentioned (putting breakpoints and write to log, etc) for debugging.

else you probably can start doing a basic one and then use it to examine your existing one.
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.