开发者

Binding values to ASP.NET Chart control

I am trying to bind some values to an ASP.NET Chart control. This is my code so far:

Dim xValues As String() = {"Option1", "Option2", "Option3", "Option4"}    
chartControl.Series(0).Points.DataBindXY(xValues, valuesAl)

valuesAl is an ArrayList开发者_如何学Go. The code to add the values to the ArrayList is as follows:

Dim cmd As New SqlCommand("StoredProcedure", Conn)
cmd.CommandType = CommandType.StoredProcedure

Dim valuesAl As New ArrayList

Dim r As SqlDataReader = cmd.ExecuteReader
While r.Read()
    valuesAl.Add(r("Value"))
End While
r.Close()

However, I am getting the following error: Enumeration already finished

Am I binding the values from the database to the Chart control correctly and if so why am I getting this error message?

Many thanks in advance for your help!


You need to make sure that your valuesA1 ArrayList ends up with the same number of values as you have in your xValues array. Internally it's looping through both collections, expecting them to have the same number, and you are getting an error because you have fewer members in the valuesA1 ArrayList.


Assuming your list value counts are the same and you want the coordinates for the same index value for each list, you can use series.Points.AddXY(), for example something like;

foreach(int i=0 ; i<valuesAl.Count; i++)
{
    series.Points.AddXY(xValue[i],valuesAl[i];
} 
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜