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.