Retrieving Min/Max X-axis values

TeeChart for ActiveX, COM and ASP
Post Reply
JAV
Newbie
Newbie
Posts: 65
Joined: Thu May 12, 2011 12:00 am

Retrieving Min/Max X-axis values

Post by JAV » Tue Sep 25, 2012 5:27 pm

Hi everyone,

We need to get the minimum and the maximum value from the x-axis in a plot. This axis is in date format. We use the MinVisibleSeriesValue function.

The code is programmed in the OnClick Event:

Code: Select all

Chart1.Axis.Bottom.MinVisibleSeriesValue  (TRUE,0)
Chart1.Axis.Bottom.MaxVisibleSeriesValue  (TRUE,0)
It works fine, but when we zoom in the plot the following error message occurs:
MinVisibleSeriesValues.jpg
Error message
MinVisibleSeriesValues.jpg (31.54 KiB) Viewed 22604 times
Please note, that the expected minimum value is 10/11/2000

Yeray
Site Admin
Site Admin
Posts: 9613
Joined: Tue Dec 05, 2006 12:00 am
Location: Girona, Catalonia
Contact:

Re: Retrieving Min/Max X-axis values

Post by Yeray » Wed Sep 26, 2012 11:01 am

Hi,

I'm trying to reproduce it here with the following code, but I don't get any error and I seem to always obtain the correct value:

Code: Select all

Private Sub Form_Load()
  TChart1.Aspect.View3D = False
  TChart1.Legend.Visible = False
  
  TChart1.AddSeries scFastLine
  TChart1.Series(0).XValues.DateTime = True
  TChart1.Series(0).FillSampleValues
End Sub

Private Sub TChart1_OnClick()
  Caption = "Min: " + FormatDateTime(TChart1.Axis.Bottom.MinVisibleSeriesValue(True, 0)) + ", Max: " + FormatDateTime(TChart1.Axis.Bottom.MaxVisibleSeriesValue(True, 0))
End Sub
Are you using the latest version available?
Could you please modify the code above or arrange a simple example project we can run as-is to reproduce the problem here?
Thanks in advance.
Best Regards,
ImageYeray Alonso
Development & Support
Steema Software
Av. Montilivi 33, 17003 Girona, Catalonia (SP)
Image Image Image Image Image Image Please read our Bug Fixing Policy

JAV
Newbie
Newbie
Posts: 65
Joined: Thu May 12, 2011 12:00 am

Re: Retrieving Min/Max X-axis values

Post by JAV » Wed Sep 26, 2012 4:28 pm

Hi Yerav,
Thank you very much for answering.
This feature was working perfect with scFasLline series. Two extra scPoint series were added and the bottom axis label style was changed to two:

Code: Select all

TChart1.Axis.Bottom.Labels.Style = 2
The current example has only one point in each scPoint serie. We noted that when this scPoint series are unchecked the error disapeared.
The images attached showed the state before and after the zoom in and how the returned values are correct with scPoint uncheked.
BeforeZoomIn.jpg
1. Before Zoom In the date values returned are correct
BeforeZoomIn.jpg (61.65 KiB) Viewed 22550 times
ZoomIn.jpg
2. Zoom In. Returned values do not corresponding with X-axis visible scale. The minimum value returns the error message reported before.
ZoomIn.jpg (50.96 KiB) Viewed 22547 times
Uncheked_OK.jpg
3. ScPoint series unchecked. Returned values Ok.
Uncheked_OK.jpg (54.87 KiB) Viewed 22564 times
We're using TeeChart8.ocx

Regards,

JAV

Yeray
Site Admin
Site Admin
Posts: 9613
Joined: Tue Dec 05, 2006 12:00 am
Location: Girona, Catalonia
Contact:

Re: Retrieving Min/Max X-axis values

Post by Yeray » Thu Sep 27, 2012 2:22 pm

Hi,

I'm still not able to reproduce any error message with TeeChart ActiveX 8 (nor with the latest v2012) and the following code.
Please, try to arrange a simple example project we can run as-is to reproduce the problem here.

Code: Select all

Private Sub Form_Load()
  TChart1.Aspect.View3D = False
  TChart1.Legend.CheckBoxes = True
  TChart1.Axis.Bottom.Labels.Angle = 90
  TChart1.Axis.Left.Logarithmic = True
  TChart1.Axis.Left.SetMinMax 1, 10000
  
  TChart1.Axis.Bottom.Labels.Style = 2
  
  Dim i, j As Integer
  Dim tmpDate As Date
  For i = 0 To 1
    tmpDate = CDate("31/08/1997")
    TChart1.AddSeries scFastLine
    With TChart1.Series(i)
      .XValues.DateTime = True
      .AddXY tmpDate, 1000, "", clTeeColor
      For j = 1 To 199
        .AddXY tmpDate + j * 7, .YValues.Value(.Count - 1) + Rnd * 100 - 50, "", clTeeColor
      Next j
    End With
  Next i
  
  TChart1.AddSeries scPoint
  TChart1.Series(TChart1.SeriesCount - 1).XValues.DateTime = True
  TChart1.Series(TChart1.SeriesCount - 1).AddXY TChart1.Series(0).XValues.Value(150), TChart1.Series(0).YValues.Maximum + 100, "", clTeeColor
  
  TChart1.AddSeries scPoint
  TChart1.Series(TChart1.SeriesCount - 1).XValues.DateTime = True
  TChart1.Series(TChart1.SeriesCount - 1).AddXY CDate("5/12/2003"), TChart1.Series(0).YValues.Maximum + 100, "", clTeeColor
  
End Sub

Private Sub TChart1_OnClick()
  Caption = "Min: " + FormatDateTime(TChart1.Axis.Bottom.MinVisibleSeriesValue(True, 0)) + ", Max: " + FormatDateTime(TChart1.Axis.Bottom.MaxVisibleSeriesValue(True, 0))
End Sub
Best Regards,
ImageYeray Alonso
Development & Support
Steema Software
Av. Montilivi 33, 17003 Girona, Catalonia (SP)
Image Image Image Image Image Image Please read our Bug Fixing Policy

JAV
Newbie
Newbie
Posts: 65
Joined: Thu May 12, 2011 12:00 am

Re: Retrieving Min/Max X-axis values

Post by JAV » Mon Oct 01, 2012 2:06 pm

Hello Yeray,
Please find attached the data that is producing the error,

Regards,

JAV
Attachments
Data.zip
(4.5 KiB) Downloaded 1167 times

Yeray
Site Admin
Site Admin
Posts: 9613
Joined: Tue Dec 05, 2006 12:00 am
Location: Girona, Catalonia
Contact:

Re: Retrieving Min/Max X-axis values

Post by Yeray » Tue Oct 02, 2012 9:18 am

Hi,

I'm still not able to reproduce any error message here.
I've transformed your xls to csv so the data it contains can be imported with the following code:

Code: Select all

Private Sub Form_Load()    
  TChart1.Aspect.View3D = False  
  TChart1.Axis.Bottom.Labels.Style = 2 'talValue
  TChart1.Axis.Left.Logarithmic = True
  
  TChart1.AddSeries scFastLine
  TChart1.AddSeries scFastLine
  TChart1.AddSeries scPoint
  TChart1.AddSeries scPoint
  TChart1.Series(0).XValues.DateTime = True
  TChart1.Series(1).XValues.DateTime = True
  TChart1.Series(2).XValues.DateTime = True
  TChart1.Series(3).XValues.DateTime = True
  
  With SeriesTextSource1
    .FileName = "C:\tmp\Data.csv"
    .HeaderLines = 1
    .FieldSeparator = ";"
    
    .Series = TChart1.Series(0)
    .AddField "X", 1
    .AddField "Y", 2
    .Active = True

    .Series = TChart1.Series(1)
    .AddField "X", 3
    .AddField "Y", 4
    .Active = True

' This works with v2012, but with v8
'    .Series = TChart1.Series(2)
'    .AddField "X", 5
'    .AddField "Y", 6
'    .Active = True
'
'    .Series = TChart1.Series(3)
'    .AddField "X", 7
'    .AddField "Y", 8
'    .Active = True
  End With
  
' I add the values manually in v8:
  TChart1.Series(2).AddXY CDate("10/11/2003"), 0, "", clTeeColor
  TChart1.Series(3).AddXY CDate("01/02/1999"), 231.48, "", clTeeColor
End Sub

Private Sub TChart1_OnClick()
  Caption = "Min: " + FormatDateTime(TChart1.Axis.Bottom.MinVisibleSeriesValue(True, 0)) + ", Max: " + FormatDateTime(TChart1.Axis.Bottom.MaxVisibleSeriesValue(True, 0))
End Sub
When I click I don't get any error message. Maybe what you mean is that you'd expect different values to be returned?
Attachments
Data.zip
(756 Bytes) Downloaded 1266 times
Best Regards,
ImageYeray Alonso
Development & Support
Steema Software
Av. Montilivi 33, 17003 Girona, Catalonia (SP)
Image Image Image Image Image Image Please read our Bug Fixing Policy

JAV
Newbie
Newbie
Posts: 65
Joined: Thu May 12, 2011 12:00 am

Re: Retrieving Min/Max X-axis values

Post by JAV » Tue Oct 02, 2012 2:40 pm

Hi Yeray,
Please note that the problem occurs while zooming on the plot. At first view it brings the correct date range, but when zooming in, it retrieves a different range from what is displayed on the chart as is shown in the previous images.
Zooming in several times produces none returned value for the minimum limit. When the scSeries are disable, the limits are returned correctly.

Regards,

JAV

Yeray
Site Admin
Site Admin
Posts: 9613
Joined: Tue Dec 05, 2006 12:00 am
Location: Girona, Catalonia
Contact:

Re: Retrieving Min/Max X-axis values

Post by Yeray » Wed Oct 03, 2012 9:05 am

Hi JAV,

I'm a bit confused. I'm not sure if we are talking about an error message or about a wrong value returned when MinVisibleSeriesValue is called.
At the first post you talked about an error message, showing a screenshot of it.
JAV wrote:It works fine, but when we zoom in the plot the following error message occurs
You still talk about an error some post later:
JAV wrote:Please find attached the data that is producing the error
But I seem to understand now it's a wrong returned value:
JAV wrote:Please note that the problem occurs while zooming on the plot. At first view it brings the correct date range, but when zooming in, it retrieves a different range from what is displayed on the chart as is shown in the previous images.
Zooming in several times produces none returned value for the minimum limit. When the scSeries are disable, the limits are returned correctly.
Best Regards,
ImageYeray Alonso
Development & Support
Steema Software
Av. Montilivi 33, 17003 Girona, Catalonia (SP)
Image Image Image Image Image Image Please read our Bug Fixing Policy

JAV
Newbie
Newbie
Posts: 65
Joined: Thu May 12, 2011 12:00 am

Re: Retrieving Min/Max X-axis values

Post by JAV » Wed Oct 03, 2012 12:40 pm

Hi Yeray,

It's indeed both. The error message appears when you zoom in several times and refers to the minimum value, and, the maximum does not return the correct value when zooming in. However, when you uncheck scPoint, the returned values ​​are correct and no error message when zooming.

Yeray
Site Admin
Site Admin
Posts: 9613
Joined: Tue Dec 05, 2006 12:00 am
Location: Girona, Catalonia
Contact:

Re: Retrieving Min/Max X-axis values

Post by Yeray » Wed Oct 03, 2012 3:25 pm

Hi,
JAV wrote:It's indeed both
Ok, thanks.
JAV wrote:The error message appears when you zoom in several times and refers to the minimum value
I'm not able to reproduce this. Can you reproduce it with the code above?
JAV wrote:the maximum does not return the correct value when zooming in. However, when you uncheck scPoint, the returned values ​​are correct and no error message when zooming.
I found this is nothing related to the logarithmic axis, neither with the datetimes. There seems to be 2 different problems here:
1. MinVisibleSeriesValue function is still considering the points in a series with FirstValueIndex=-1 and LastValueIndex=-1. Find below a manual implementation in VB6 of the same function, correcting this:

Code: Select all

Private Sub Form_Load() 
  TChart1.Aspect.View3D = False
 
  TChart1.AddSeries scFastLine
  TChart1.AddSeries scPoint
  TChart1.Series(0).FillSampleValues 10
  TChart1.Series(1).AddXY TChart1.Series(0).XValues.Value(5), TChart1.Series(0).YValues.Value(5), "", clTeeColor
End Sub

Private Sub TChart1_OnAfterDraw()
  Caption = "Min: " + Format$(MinVisibleSeriesValue(TChart1, TChart1.Axis.Bottom, True, 0)) + ", Max: " + Format$(MaxVisibleSeriesValue(TChart1, TChart1.Axis.Bottom, True, 0))
End Sub

Private Function MinVisibleSeriesValue(ByVal Chart As TChart, ByVal Axis As IAxis, ByVal AllSeries As Boolean, ByVal SeriesIndex As Integer) As Double
  MinVisibleSeriesValue = MaxMinVisibleValue(Chart, Axis, False, AllSeries, SeriesIndex)
End Function

Private Function MaxVisibleSeriesValue(ByVal Chart As TChart, ByVal Axis As IAxis, ByVal AllSeries As Boolean, ByVal SeriesIndex As Integer) As Double
  MaxVisibleSeriesValue = MaxMinVisibleValue(Chart, Axis, True, AllSeries, SeriesIndex)
End Function

Private Function MaxMinVisibleValue(ByVal Chart As TChart, ByVal Axis As IAxis, ByVal IsMax As Boolean, ByVal AllSeries As Boolean, ByVal SeriesIndex As Integer) As Double
  Dim i, j, firstSeries, startSeries, endSeries, a, b As Integer
  Dim tmpResult, tmpVal As Double
  Dim firstTime As Boolean
  
  firstSeries = -1
  firstTime = True
  tmpResult = 0
  
  With Chart
    If AllSeries Then
      For i = 0 To .SeriesCount - 1
        If (.Series(i).Active) Then
          firstSeries = i
          Exit For
        End If
      Next i
    Else
      firstSeries = SeriesIndex
    End If

    If (firstSeries >= 0) And (firstSeries < .SeriesCount) Then
      If AllSeries = True Then
        startSeries = 0
        endSeries = .SeriesCount - 1
      Else
        startSeries = SeriesIndex
        endSeries = SeriesIndex
      End If
      For i = startSeries To endSeries
        If ((SeriesAssociatedToAxis(.Series(i), Axis)) And (.Series(i).Active)) Then
          If (.Series(i).FirstValueIndex <> -1) And ((.Series(i).LastValueIndex <> -1)) Then
            For j = .Series(i).FirstValueIndex To .Series(i).LastValueIndex
              tmpVal = .Series(i).XValues.Value(j)

              If firstTime Then
                tmpResult = tmpVal
                firstTime = False
              Else
                If (IsMax) Then
                  If (tmpVal > tmpResult) Then
                    tmpResult = tmpVal
                  End If
                Else
                  If (tmpVal < tmpResult) Then
                    tmpResult = tmpVal
                  End If
                End If
              End If
            Next j
          End If
        End If
      Next i
    End If
  End With
  
  MaxMinVisibleValue = tmpResult
End Function

Private Function SeriesAssociatedToAxis(ByVal Series As ISeries, ByVal Axis As IAxis) As Boolean
  SeriesAssociatedToAxis = Series.UseAxis And (( _
                           ((Series.HorizontalAxis = aBothHorizAxis) Or (Series.HorizontalAxis = aBottomAxis))))
End Function
2. When you zoom or scroll the chart so the series with a unique point disappears on the right side, this series still has FirstValueIndex=0 and LastValueIndex=0, when both should be -1. I've added it to the defect list to be fixed in future releases (VCL: TV52016374).
In the meanwhile, you could calculate the FirstValueIndex and LastValueIndex manually, instead of using the provided properties, and use them in the MaxMinVisibleValue function above.
Best Regards,
ImageYeray Alonso
Development & Support
Steema Software
Av. Montilivi 33, 17003 Girona, Catalonia (SP)
Image Image Image Image Image Image Please read our Bug Fixing Policy

JAV
Newbie
Newbie
Posts: 65
Joined: Thu May 12, 2011 12:00 am

Re: Retrieving Min/Max X-axis values

Post by JAV » Mon Oct 08, 2012 2:26 pm

ok, thank you very much, please let us know when this bug is corrected.

regards,

JAV

Post Reply