Bottom Axis Time Base Configuration Problems

TeeChart for Microsoft Visual Studio .NET, Xamarin Studio (Android, iOS & Forms) & Monodevelop.
Post Reply
tirby
Newbie
Newbie
Posts: 84
Joined: Mon Mar 16, 2009 12:00 am

Bottom Axis Time Base Configuration Problems

Post by tirby » Fri Nov 13, 2015 9:48 pm

Hello,

I can't figure out how to make this work.
I just want to allow the user to swap the Bottom Axis values based on ListBox7 selection (Numeric or Time)
If the user selects the first item (Numeric), the code works as I expect.
If the user selects the second item (Time) this is where the problem arises.

Code: Select all

Private Sub ListBox7_SelectedIndexChanged(sender As System.Object, e As System.EventArgs) Handles ListBox7.SelectedIndexChanged
        'Axis Mode Select
        Dim aa As Integer
        Dim StartTime As Date
        Dim EndTime As Date
        Dim PlotAxisMode As Integer

       StartTime = Now
'        EndTime =  Now + 60 Minutes TimeAdd(Job.StartTime, Double.Parse(TextBox11.Text))
'TimeAdd function does work correctly

        PlotAxisMode = ListBox7.SelectedIndex
        Select Case ListBox7.SelectedIndex
            Case 0      'Numeric
                For aa = 0 To 7
                    frm1.TChart1.Series(aa).XValues.DateTime = False
                Next aa
                frm1.TChart1.Axes.Bottom.Labels.ValueFormat = "#,##0"
                frm1.TChart1.Axes.Bottom.Minimum = 0
                frm1.TChart1.Axes.Bottom.Maximum = 60

            Case 1      'Time
                For aa = 0 To 7
                    frm1.TChart1.Series(aa).XValues.DateTime = True
                Next aa
                frm1.TChart1.Axes.Bottom.Labels.DateTimeFormat = "MM/dd/yyyy hh:mm tt"
                frm1.TChart1.Axes.Bottom.Labels.ValueFormat = "#0:00"

                'frm1.TChart1.Axes.Bottom.Minimum = StartTime.ToOADate()
                'frm1.TChart1.Axes.Bottom.Maximum = EndTime.ToOADate()
        End Select

End Sub
This first Image is the "Numeric" Mode screen shot.
Note the number of vertical lines as well as the starting value of 0.
This is what I expected.
Screen1.png
Screen1.png (46.69 KiB) Viewed 10990 times
On this Image, in "Time" mode, the starting value is "12/30/1899 12:00 AM".
I want it to be display whatever "Now" is ("11/13/2015 3:40 PM"). The ending value should display Now + 60 Minutes.
Also, it should have the same number of Vertical lines as in the 1st screen shot.
Screen2.png
Screen2.png (47.02 KiB) Viewed 10982 times
The only thing that should change is the text for the Bottom Axis.

In the code, the last 2 items are commented out.
If they are allowed to execute, only 1 vertical line appears, and the Bottom Axis text is "12/15/1963 12:00 AM"

So, What am I doing wrong?

Christopher
Guru
Posts: 1603
Joined: Fri Nov 15, 2002 12:00 am

Re: Bottom Axis Time Base Configuration Problems

Post by Christopher » Mon Nov 16, 2015 10:46 am

Hello,

You could try something like this:

Code: Select all

    TChart1.Header.Text = "Job Name"
    TChart1.Axes.Bottom.Minimum = 0
    TChart1.Axes.Bottom.Maximum = 24
    AddHandler TChart1.GetAxisLabel, AddressOf GetAxisLabel

    TChart1.Draw()

  End Sub

  Private Sub GetAxisLabel(sender As Object, e As GetAxisLabelEventArgs)
    Dim val As Double
    Dim now, label As DateTime

    If (DirectCast(sender, Axis).Equals(TChart1.Axes.Bottom)) And (Not CheckBox1.Checked) Then
      val = Convert.ToDouble(e.LabelText)
      now = DateTime.Now
      label = now.AddHours(val)
      e.LabelText = label.ToString(TChart1.Axes.Bottom.Labels.DateTimeFormat)
    End If
  End Sub

  Private Sub CheckBox1_CheckedChanged(sender As Object, e As EventArgs) Handles CheckBox1.CheckedChanged
    TChart1.Legend.Visible = False
    TChart1.Panel.MarginBottom = 30
    TChart1.Axes.Bottom.Labels.Angle = 90
    TChart1.Axes.Bottom.Labels.DateTimeFormat = "yyyy/MM/dd HH:mm"
    TChart1.Invalidate()
  End Sub
Which here gives me this:
numeric.PNG
numeric.PNG (16.31 KiB) Viewed 10964 times
Best Regards,
Christopher Ireland / Development & Support
Steema Software
Avinguda Montilivi 33, 17003 Girona, Catalonia
Tel: 34 972 218 797
http://www.steema.com
Instructions - How to post in this forum

tirby
Newbie
Newbie
Posts: 84
Joined: Mon Mar 16, 2009 12:00 am

Re: Bottom Axis Time Base Configuration Problems

Post by tirby » Sat Nov 21, 2015 7:01 pm

Christopher, Thanks for looking at this.

I tried to implement your suggestion with little success.

Please see the attached screenshot: Screen2A.png
This is what the bottom axis should look like after selecting "Time Mode".
Referring to my original Screen1.png screenshot, it is in "Numeric Mode".
The only differences are the actual text displayed and the orientation of the text.
The orientation is not a problem for me to set, however getting the text (Now -->> Now + 60 minutes) is a problem.

In my code, I have the Maximum value adjustable, and the time base is select-able as well (seconds, minutes, hours, days), however for simplicity in correcting this problem I have chosen 60 minutes.

I have a routine that adds (plots) a new point every 1 second.

Thanks
Screen2A.png
Screen2A.png (53.29 KiB) Viewed 10947 times
(edited/modified with MSPaint)

Christopher
Guru
Posts: 1603
Joined: Fri Nov 15, 2002 12:00 am

Re: Bottom Axis Time Base Configuration Problems

Post by Christopher » Mon Nov 23, 2015 9:22 am

Hello,
tirby wrote: I tried to implement your suggestion with little success.
As mentioned in the "Instructions - HowTo post in this forum" (here), would you please be so kind as to send us a Short, Self Contained, Correct Example (SSCCE) (explained here) with which we can reproduce your issue here?
Best Regards,
Christopher Ireland / Development & Support
Steema Software
Avinguda Montilivi 33, 17003 Girona, Catalonia
Tel: 34 972 218 797
http://www.steema.com
Instructions - How to post in this forum

tirby
Newbie
Newbie
Posts: 84
Joined: Mon Mar 16, 2009 12:00 am

Re: Bottom Axis Time Base Configuration Problems

Post by tirby » Tue Nov 24, 2015 9:49 pm

I came up with an alternative method to achieve my goal.
It has one small issue however, but I will post as a new Issue.
Meantime, here's my fix!

Using buttons to select the mode:

Code: Select all

    Private Sub Button1_Click(sender As System.Object, e As System.EventArgs) Handles Button1.Click
        'Numeric Mode
        Dim aa As Integer

        For aa = 0 To 7
            TChart1.Series(aa).XValues.DateTime = False
        Next aa
        TChart1.Axes.Bottom.Labels.ValueFormat = "#,##0"
        TChart1.Axes.Bottom.Minimum = 0
        TChart1.Axes.Bottom.Maximum = 60
        TChart1.Axes.Bottom.Labels.Angle = 0
        TChart1.Axes.Bottom.Increment = (TChart1.Axes.Bottom.Maximum - TChart1.Axes.Bottom.Minimum) / 12

    End Sub

    Private Sub Button2_Click(sender As System.Object, e As System.EventArgs) Handles Button2.Click
        'Time Mode
        Dim aa As Integer
        Dim bb As DateTime
        Dim cc As DateTime

        For aa = 0 To 7
            TChart1.Series(aa).XValues.DateTime = True
        Next aa

        TChart1.Axes.Bottom.Labels.DateTimeFormat = "HH:mm"
        TChart1.Axes.Bottom.Labels.Angle = 90
        bb = Now
        cc = bb.AddMinutes(60)
        TChart1.Axes.Bottom.Minimum = bb.ToOADate()
        TChart1.Axes.Bottom.Maximum = cc.ToOADate()
        TChart1.Axes.Bottom.Increment = (TChart1.Axes.Bottom.Maximum - TChart1.Axes.Bottom.Minimum) / 12

    End Sub

Post Reply