Page 1 of 1
Finding optimal Min Max Axis after zooming
Posted: Tue Oct 12, 2010 12:48 pm
by 9533057
Hi,
How can I implement a function to find optimal min max axis after zooming ?
I use
SetMinMax function but it does not work, the max value of my serie (for current zoom range) is not on the top of the max axis
Code: Select all
Private Sub AxTChart_OnZoom(ByVal sender As Object, ByVal e As System.EventArgs) Handles AxTChart.OnZoom
Dim Min As Double
Dim Max As Double
Min = AxTChart.Series(0).MinVisibleValue(1)
Max = AxTChart.Series(0).MaxVisibleValue(1)
AxTChart.Axis.Left.SetMinMax(Min, Max)
End Sub
- zoom00.jpg (101.52 KiB) Viewed 11420 times
- zoom01.jpg (77.79 KiB) Viewed 11416 times
Thanks for your help (I did not found any topic about this
)
Guilz
Re: Finding optimal Min Max Axis after zooming
Posted: Wed Oct 13, 2010 8:55 am
by narcis
Hi Guilz,
You could do something as the local minimum and maximum example suggested
here. You could use series' FirstVisibleIndex and LastVisibleIndex as first and last arguments. This is a TeeChart .NET thread but same should apply to ActiveX version.
Hope this helps.
Re: Finding optimal Min Max Axis after zooming
Posted: Wed Oct 13, 2010 9:21 am
by yeray
Hi Guilz,
Alternatively, you could try forcing a chart repaint before using the MinVisibleValue and MaxVisibleValue functions. Something like:
Code: Select all
AxTChart.Environment.InternalRepaint
Re: Finding optimal Min Max Axis after zooming
Posted: Wed Oct 13, 2010 9:45 am
by 9533057
Hi Yeray,
Code: Select all
AxTChart.Environment.InternalRepaint
is working fine with 1 serie but...
let's consider my new example:
- zoom02.jpg (225 KiB) Viewed 11413 times
Code: Select all
Private Sub AxTChart_OnZoom(ByVal sender As Object, ByVal e As System.EventArgs) Handles AxTChart.OnZoom
Dim Min As Double = 99999999
Dim Max As Double = -99999999
AxTChart.Environment.InternalRepaint()
For i = 0 To AxTChart.SeriesCount - 1
If AxTChart.Series(i).MinVisibleValue(1) < Min Then
Min = AxTChart.Series(i).MinVisibleValue(1)
End If
If AxTChart.Series(i).MaxVisibleValue(1) > Max Then
Max = AxTChart.Series(i).MaxVisibleValue(1)
End If
Next
AxTChart.Axis.Left.SetMinMax(Min, Max)
End Sub
And the result is not correct as bellow...
- zoom03.jpg (202.96 KiB) Viewed 11410 times
How can take in account the left and right axis ?
Thanks for your help...
Guilz
Re: Finding optimal Min Max Axis after zooming
Posted: Wed Oct 13, 2010 12:48 pm
by yeray
Hi Guliz,
In that case I'm afraid you should control the full zoom manually as in the example Narcis suggested.
If you find problems with it, don't hesitate to let us know.
Re: Finding optimal Min Max Axis after zooming
Posted: Wed Oct 13, 2010 1:11 pm
by 9533057
Yeray,
I'm afraid
Zoomed Event does not exist in Teechart v8....
Could you give us a sample code in VB to do that because the topic is confusing...
(A simple example with 2 differents axis (left and right) and 1 serie associated to right axis and another one to left axis) with the method to fit exactly the 2 series to the zoomed area will be very usefull !
Thanks a lot for us
Guilz
Re: Finding optimal Min Max Axis after zooming
Posted: Thu Oct 14, 2010 8:34 am
by yeray
Hi Guilz,
Finally, it wasn't so trivial...
I've made the example with Point series because it's easier (with Line series you may also want to consider the line segments, not only the points in the area selected)
Code: Select all
Dim MouseDownX, MouseDownY, MouseUpX, MouseUpY As Integer
Private Sub Form_Load()
TeeCommander1.ChartLink = TChart1.ChartLink
TChart1.Legend.Visible = False
TChart1.Aspect.View3D = False
Dim i As Integer
For i = 0 To 1
TChart1.AddSeries scPoint
TChart1.Series(i).FillSampleValues 100
TChart1.Series(i).asPoint.Pointer.VerticalSize = 2
TChart1.Series(i).asPoint.Pointer.HorizontalSize = 2
If i Mod 2 = 0 Then
TChart1.Series(i).VerticalAxis = aRightAxis
End If
Next i
TChart1.Axis.Left.GridPen.Visible = False
End Sub
Private Sub TChart1_OnMouseDown(ByVal Button As TeeChart.EMouseButton, ByVal Shift As TeeChart.EShiftState, ByVal X As Long, ByVal Y As Long)
MouseDownX = X
MouseDownY = Y
End Sub
Private Sub TChart1_OnMouseUp(ByVal Button As TeeChart.EMouseButton, ByVal Shift As TeeChart.EShiftState, ByVal X As Long, ByVal Y As Long)
MouseUpX = X
MouseUpY = Y
End Sub
Private Sub TChart1_OnZoom()
With TChart1.Axis.Left
.SetMinMax .CalcPosPoint(MouseUpY), .CalcPosPoint(MouseDownY)
End With
With TChart1.Axis.Right
.SetMinMax .CalcPosPoint(MouseUpY), .CalcPosPoint(MouseDownY)
End With
TChart1.Environment.InternalRepaint
Dim TopPos, BottomPos, tmp, offset As Integer
offset = 2
TopPos = -1
BottomPos = -1
Dim i, j As Integer
For i = 0 To TChart1.SeriesCount - 1
For j = TChart1.Series(i).FirstValueIndex To TChart1.Series(i).LastValueIndex - 1
tmp = -1
If TChart1.Series(i).VerticalAxis = aLeftAxis Then
If TChart1.Series(i).YValues.Value(j) <= TChart1.Axis.Left.Maximum And TChart1.Series(i).YValues.Value(j) >= TChart1.Axis.Left.Minimum Then
tmp = TChart1.Axis.Left.CalcYPosValue(TChart1.Series(i).YValues.Value(j))
End If
ElseIf TChart1.Series(i).VerticalAxis = aRightAxis Then
If TChart1.Series(i).YValues.Value(j) <= TChart1.Axis.Right.Maximum And TChart1.Series(i).YValues.Value(j) >= TChart1.Axis.Right.Minimum Then
tmp = TChart1.Axis.Right.CalcYPosValue(TChart1.Series(i).YValues.Value(j))
End If
End If
If tmp <> -1 Then
If TopPos = -1 Or tmp < TopPos Then
TopPos = tmp
End If
If BottomPos = -1 Or tmp > BottomPos Then
BottomPos = tmp
End If
End If
Next j
Next i
If BottomPos <> -1 And TopPos <> -1 Then
TChart1.Axis.Left.SetMinMax TChart1.Axis.Left.CalcPosPoint(BottomPos + offset), TChart1.Axis.Left.CalcPosPoint(TopPos - offset)
TChart1.Axis.Right.SetMinMax TChart1.Axis.Right.CalcPosPoint(BottomPos + offset), TChart1.Axis.Right.CalcPosPoint(TopPos - offset)
End If
End Sub
Re: Finding optimal Min Max Axis after zooming
Posted: Thu Oct 14, 2010 9:16 am
by 9533057
Hi Yeray,
Thanks a lot for your reply - it is working like a charm
In my case, I have added the code bellow at the begining of TChart1_OnZoom procedure
Code: Select all
If TChart1.Zoom.Direction = tzdHorizontal Then
MouseDownY = TChart1.Axis.Left.IStartPos
MouseUpY = TChart1.Axis.Left.IEndPos
End If
to ensure it will be working even if user change the zoom direction property (both->tzdHorizontal)
Regards,
Guilz
Re: Finding optimal Min Max Axis after zooming
Posted: Thu Oct 14, 2010 10:40 am
by yeray
Hi Guilz,
I'm glad to hear that!