Soldato
I'm at it again!
The idea is to dynamically create multiple x series based on column in sqlsource. Y is the count of tickets and x is the weekno.
A sql view which returns columns on a data-set covering a period of 12 months:
I then have the following code:
However, I get the following ASP error when viewing the page
"Index was out of range. Must be non-negative and less than the size of the collection.
Parameter name: index"
Any pointers would be greatly appreciated.
TIA!
The idea is to dynamically create multiple x series based on column in sqlsource. Y is the count of tickets and x is the weekno.
A sql view which returns columns on a data-set covering a period of 12 months:
I then have the following code:
Code:
Protected Sub Page_Load(ByVal sender As Object, ByVal e As EventArgs) Handles Me.Load
If Not Me.IsPostBack Then
'Fetch the data from database.
Dim query As String = "SELECT TickC, CODE, Year, Week FROM SQLVIEW ORDER BY Year, Week"
Dim dt As DataTable = GetData(query)
'Get the DISTINCT subcodes.
Dim codes As List(Of String) = (From p In dt.AsEnumerable()
Select p.Field(Of String)("CODE")).Distinct().ToList()
'Loop through the subcodes.
For Each subcode As String In codes
'Get the weekno for each subcode.
Dim x As Integer() = (From p In dt.AsEnumerable()
Where p.Field(Of String)("CODE") = subcode
Order By p.Field(Of Integer)("Week")
Select p.Field(Of Integer)("Week")).ToArray()
'Get the Total of tickes for each subcode.
Dim y As Integer() = (From p In dt.AsEnumerable()
Where p.Field(Of String)("CODE") = subcode
Order By p.Field(Of Integer)("Week")
Select p.Field(Of Integer)("TickC")).ToArray()
'Add Series to the Chart.
Chart1.Series.Add(New Series(subcode))
Chart1.Series(subcode).IsValueShownAsLabel = True
Chart1.Series(subcode).BorderWidth = 2
Chart1.Series(subcode).ChartType = SeriesChartType.Line
Chart1.Series(subcode).Points.DataBindXY(x, y)
Next
Chart1.Legends(0).Enabled = True
End If
End Sub
Private Shared Function GetData(ByVal query As String) As DataTable
Dim constr As String = ConfigurationManager.ConnectionStrings("CONNECTION").ConnectionString
Using con As SqlConnection = New SqlConnection(constr)
Using sda As SqlDataAdapter = New SqlDataAdapter(query, con)
Dim dt As DataTable = New DataTable()
sda.Fill(dt)
Return dt
End Using
End Using
End Function
"Index was out of range. Must be non-negative and less than the size of the collection.
Parameter name: index"
Any pointers would be greatly appreciated.
TIA!