I'm working on a data handling page for a customer.
I've made a chart that shows data from my SQL server.
On my x-axis I have a date but the whole column contains also a timestamp e.g. "08/01/2019 14:34", but is not visible.
As seen on the linked picture below, how do I format the x-axis value to only show the time, or the whole value from the dbo, if possible?
Do I have to format the size of the chart on the screen, if so, how do I do that? I've tried looking for an option in the chart settings.
Here's a snippet of the code:
Private Sub dgvSiteChart() 'Load data from dbo
DateandTimeString24H = "'" & Date.Now.Year & "-" & Date.Now.Month & "-" & Date.Now.Day & " 00:00:00.000'" & " And " & "'" & Date.Now.Year & "-" & Date.Now.Month & "-" & Date.Now.Day & " 23:59:59.000'"
SQLCon = New SqlConnection
SQLCon.ConnectionString = "Data Source=" & System.Net.Dns.GetHostName() & "\KVMSQL;Initial Catalog=MHA;User ID=#####;Password =######"
Dim READER As SqlDataReader
Try
SQLCon.Open()
Dim Query As String
Query = "SELECT DateAndTime,Tagindex,Val FROM dbo.FT WHERE tagindex=0 and DateAndTime between " & DateandTimeString24H & "ORDER BY DateAndTime"
SQLCmd = New SqlCommand(Query, SQLCon)
READER = SQLCmd.ExecuteReader
While READER.Read
chrtReportMchn.Series("LOG").Points.AddXY(READER("DateAndTime"), READER("Val"))
End While
SQLCon.Close()
Catch ex As Exception
MsgBox(ex.Message)
Finally
SQLCon.Dispose()
End Try
End Sub
Date and time format is dd/MM/yyyy HH:mm(24H)
.
UPDATE: 10/1-19
I've figured it out, with the help of @Markus with his comment.
The code is edited with FORMAT(CAST(DateAndTime as time), 'hh\:mm\ ')
put in front of the DateAndTime
.
Try
SQLCon.Open()
Dim Query As String
Query = "SELECT FORMAT(CAST(DateAndTime as time), 'hh\:mm\ ') DateAndTime,Tagindex,Val FROM dbo.FT WHERE tagindex=0 and DateAndTime between " & DateandTimeString24H & "ORDER BY DateAndTime"
SQLCmd = New SqlCommand(Query, SQLCon)
READER = SQLCmd.ExecuteReader
While READER.Read