Hi,
I am not sure what I am doing wrong here. I am trying to render a chart but keep getting :
System.IndexOutOfRangeException: Index was outside the bounds of the array. Source Error:
Line 36: While reader.Read()
Line 37:
Line 38: chartValues(CInt(reader.GetValue(1))) = reader.GetValue(1)
Line 39:
Line 40:
|
Protected Sub Render_Chart()
Dim constring As String = WebConfigurationManager.ConnectionStrings("ERDASHConnectionString").ToString()
Dim myConn As SqlConnection = New SqlConnection(constring)
Dim commandText As String = "SELECT [AtDoor], [Ped_Patients] PEDS FROM [ERDASH].[dbo].[Volume1] where [AtDoor] >= DATEADD(DAY, -1, CAST(GETDATE() AS DATE)) AND[AtDoor] < CAST(CAST(GETDATE() AS DATE) AS DATETIME)"
Dim myComm As SqlCommand = New SqlCommand(commandText, myConn)
myConn.Open()
Dim reader As SqlDataReader = myComm.ExecuteReader()
Dim chartValues As Object() = New Object(1) {}
If reader.HasRows Then
While reader.Read()
chartValues(CInt(reader.GetValue(1))) = reader.GetValue(1)
End While
Else
Console.WriteLine("No rows found.")
End If
reader.Close()
Dim constring2 As String = WebConfigurationManager.ConnectionStrings("ERDASHConnectionString").ToString()
Dim myConn2 As SqlConnection = New SqlConnection(constring2)
Dim commandText2 As String = "SELECT [AtDoor],[Adult_Patients] FROM [ERDASH].[dbo].[Volume1] where [AtDoor] >= DATEADD(DAY, -1, CAST(GETDATE() AS DATE)) AND[AtDoor] < CAST(CAST(GETDATE() AS DATE) AS DATETIME)"
Dim myComm2 As SqlCommand = New SqlCommand(commandText2, myConn2)
myConn2.Open()
Dim reader2 As SqlDataReader = myComm2.ExecuteReader()
Dim chartValues2 As Object() = New Object(1) {}
If reader2.HasRows Then
While reader2.Read()
chartValues2(CInt(reader2.GetValue(1)) - 1) = reader2.GetValue(1)
End While
Else
Console.WriteLine("No rows found.")
End If
reader2.Close()
Dim chart As DotNet.Highcharts.Highcharts = New DotNet.Highcharts.Highcharts("chart").InitChart(New Chart With {
.DefaultSeriesType = ChartTypes.Column
}).SetTitle(New Title With {
.Text = "Monthly #s",
.X = -20
}).SetTooltip(New Tooltip With {
.Formatter = "function() { return '<b>' + this.x + '</b><br/>' + this.series.name + ': ' + this.y + '<br/>' + 'Total: ' + this.point.stackTotal;}"
}).SetYAxis(New YAxis With {
.Title = New YAxisTitle With {
.Text = "Patients"
},
.Min = 0
}).SetPlotOptions(New PlotOptions With {
.Column = New PlotOptionsColumn With {
.Stacking = Stackings.Normal,
.DataLabels = New PlotOptionsColumnDataLabels With {
.Enabled = True
}
}
}).SetSubtitle(New Subtitle With {
.Text = "Test",
.X = -20
}).SetXAxis(New XAxis With {
.Categories = {"Past Day"}
}).SetSeries({New Series With {
.Name = "# Test",
.Data = New Data(chartValues)
}, New Series With {
.Name = "# cats",
.Data = New Data(chartValues2)
}})
ltrChart1.Text = chart.ToHtmlString()
End Sub
Private Sub form1_Load(sender As Object, e As EventArgs) Handles form1.Load
Render_Chart()
End Sub
My database design:
AtDoor = date
Adult_Patients = int
Ped_Patients = int
thank you for your help!