Click here to Skip to main content
15,885,985 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
hello!

I have problem to show hours in graph.

I have this registers in DataBase MySQL:
VB
hora:                temperatura:
8:34:14             +025.52
8:35:15             +026.43
8:36:16             +026.24
8:37:17             +027.50
   .                    .
   .                    .
   .                    .
   .                    .


so I'm graphing it:
https://i.stack.imgur.com/RZxQz.jpg

the XAxis is showing the hours "70000, 80000, 90000,...."
I want the Xaxis show hours like "7:00:00 8:00:00 9:00:00"

so, I have the hours stored in database.

this is the code:

Private Sub CreateGraph(ByVal zgc As ZedGraphControl)
       Try
           Dim query As String = "SELECT * from termocuplas WHERE id_modulo = '#03H' AND fecha = '2019-08-27' ORDER BY fecha ASC, hora ASC"    'ORDER BY fecha ASC
           Dim connection As New MySqlConnection(connStr)
           Dim cmd As New MySqlCommand(query, connection)
           connection.Open()
           reader = cmd.ExecuteReader()

           Dim myPane As GraphPane = zgc.GraphPane
           myPane.Title.Text = "Termocupla"
           myPane.XAxis.Title.Text = "Tiempo(hh:mm:ss)"
           myPane.XAxis.Scale.MagAuto = False

           myPane.YAxis.Title.Text = "Temperatura °C"
           myPane.YAxis.Scale.MagAuto = False

           Dim list1 = New PointPairList()
           Dim y As Single
           Dim x As Single

           If reader.Read Then
               While reader.Read()
                   y = Convert.ToSingle(Replace(reader.GetString(3), ".", ","))
                   x = Convert.ToSingle(Replace(reader.GetString(11), ":", ""))
                   list1.Add(x, y)
               End While
               reader.Close()
           Else
               MessageBox.Show("Nothing")
           End If

           Dim myCurve As LineItem = myPane.AddCurve("Termocupla Vapor", list1, Color.Red, SymbolType.None)
           myCurve.Line.Fill = New Fill(Color.White, Color.Red, 45.0F) ' Make the symbols opaque by filling them with white
           myCurve.Symbol.Fill = New Fill(Color.White) ' Fill the axis background with a color gradient
           myPane.Chart.Fill = New Fill(Color.White, Color.LightGoldenrodYellow, 45.0F) ' Fill the pane background with a color gradient
           myPane.Fill = New Fill(Color.White, Color.FromArgb(220, 220, 255), 45.0F)
           zgc.AxisChange()
           connection.Close()
       Catch ex As Exception
           Console.WriteLine(ex.Message)
       End Try

   End Sub


What I have tried:

so, what can I do to show the hours correctly?
Posted
Updated 27-Aug-19 7:42am

You probably need to store the "x value" as a "date time".

Then when you specify the "x axis", there should be a provision to specify the format of the "major / minor" tick "labels".

Or there could be an "on load" event for the item or something similar that allows for trapping the label for rotating etc.
 
Share this answer
 
Comments
Member 14560567 27-Aug-19 12:16pm    
I did this:

Dim x As System.DateTime
and inside of 'While' =
x = reader.GetString("hora")

but this is the error now=

Error 1 Overload resolution failed because no accessible 'Add' can be called with these arguments:
'Public Sub Add(x As Double, y As Double)': Conversion from 'Date' to 'Double' requires calling the 'Date.ToOADate' method.
'Public Sub Add(x() As Double, y() As Double)': Value of type 'Date' cannot be converted to '1-dimensional array of Double'.
'Public Sub Add(x() As Double, y() As Double)': Value of type 'Single' cannot be converted to '1-dimensional array of Double'.
the solution is:
Dim list1 = New PointPairList()
Dim y As Single
Dim x As Single
Dim c As Date

      If reader.Read Then
                While reader.Read()
                    y = Replace(reader.GetString(3), ".", ",")
                    c = Convert.ToDateTime(reader.GetString(11))
                    x = c.ToOADate()
                    list1.Add(x, y)
                End While
                reader.Close()
            End If


it works!!!! (Y) thanks so much!
 
Share this answer
 
v2

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900