Get Time and Date on X-Axis

Fedda

New member
Joined
Dec 4, 2021
Messages
1
Programming Experience
Beginner
First of all, I have been playing with VB coding for a couple of weeks, so bare with me :)

I have made a Chart to show values from Soil moisture sensors connected to Arduino, and it all works out just fine.

Now I'm stuck. I would like to get the X-Axis to show current time and date, but it was more difficult then i imagined.. I have managed to get Current Date and Time to be displayed in a Label, but I also like to get it to show in the X-Axis..

Anyone who can help out a beginner, and tell me how to make this work?

I'll post a part of my code and a screenshot.

VB.NET:
Imports System.IO.Ports
Imports System.Windows.Forms.DataVisualization.Charting


Public Class Form1
    Private Delegate Sub myDelegate(Buffer As String)
    Dim txt As String

    Private Sub Form1_Load(sender As Object, e As EventArgs) Handles MyBase.Load
        FormBorderStyle = FormBorderStyle.None
        WindowState = FormWindowState.Maximized
        ConnectionPanel.Focus()
        ComboBoxBaudRate.SelectedIndex = 0

        Chart1.ChartAreas(0).AxisX.ScrollBar.IsPositionedInside = False
        Chart1.ChartAreas(0).AxisX.ScaleView.SmallScrollMinSize = 5
        Chart1.Series(0).XValueType = ChartValueType.DateTime
        Chart1.ChartAreas(0).AxisX.LabelStyle.Format = "hh:mm:ss"
    End Sub


    Private Sub TimerSerial_Tick(sender As Object, e As EventArgs) Handles TimerSerial.Tick
        txt = Now.Hour.ToString("00") & ":"
        txt &= Now.Minute.ToString("00") & ":"
        txt &= Now.Second.ToString("00")
        txt &= Now.ToString(".  dd MM yyyy")
        Label6.Text = txt
    End Sub

Skjermbilde.PNG
 

JohnH

VB.NET Forum Moderator
Staff member
Joined
Dec 17, 2005
Messages
15,603
Location
Norway
Programming Experience
10+
Set a LabelStyle.Format that includes both:

Take into account these properties of ChartAreas(0).AxisX:
 
Top Bottom