|
ViewPortLeft and HScroll |
Posted by svein berg on Mar-23-2019 02:37 |
|
Hi.
I'm charting some live data, and are using a viewport to see portions of it.
I can scroll back and forth, but not all the way to the end of the latest data. (new data every sec.)
In form_load I have;
Me.ChartViewer1.ScrollDirection = cvHorizontal
'Me.ChartViewer1.ZoomDirection = cvHorizontal
In drawChart I constantly update the Viewport with NewX as the desired Viewport in sec.
If Livedata > NewX Then
newViewPortWidth = NewX / Livedata
If (Abs(ChartViewer1.ViewportWidth - newViewPortWidth) > 0.00001 * ChartViewer1.ViewportWidth) Then
' Set the view port based on the duration
dont = True 'Dont fire the ViewPortChanged
ChartViewer1.ViewportWidth = newViewPortWidth
Call ChartViewer1.updateViewPort(True, True)
dont = False
End If
End If
When debugging I find that the view.viewportleft is encreasing to much, so
I get view.viewportleft +viewportwidth =1 to fast to be able to scroll all the way to the end.
I'm not setting the viewportleft anywhere, and asume its updated from the ViewPortChanged event where I have;
If needUpdateChart Then
Call drawChart(ChartViewer1)
End If
My hat off to any help!
Regards svein
ps. Running win10, VB6 and CD 6.0 |
Re: ViewPortLeft and HScroll |
Posted by Peter Kwan on Mar-26-2019 00:52 |
|
Hi svein,
The end of the latest data is at "ViewPortLeft + ViewPortWidth", which must not be larger than 1.
In your code in "If Livedata > NewX Then ...", your code update the ViewPortWidth, but does not update the ViewPortLeft. It may cause the following problem:
(a) If the newViewPortWidth is larger than the old ViewPortWidth, then after the update, it may be possible for "ViewPortLeft + ViewPortWidth" to exceed 1. This is invalid. So when you call updateViewPort, ChartDirector needs to reduce the ViewPortLeft to make "ViewPortLeft + ViewPortWidth" not larger than 1.
(b) If the newViewPortWidth is less than the old ViewPortWidth, then after the update, the "ViewPortLeft + ViewPortWidth" will be reduced. So if before the update, the "ViewPortLeft + ViewPortWidth" is 1, after the update, it will be less than 1.
If you are using VB6, to troubleshoot the issue, you may print the viewport positions to the Debugger window, using:
Debug.Print ("Left=" & Me.ChartViewer1.ViewPortLeft & " Width=" & Me.ChartViewer1.ViewPortWidth & " Right=" & (Me.ChartViewer1.ViewPortLeft + Me.ChartViewer1.ViewPortWidth))
You may put this line in the "If Livedata > NewX Then ..." before and after the updating the viewport, and also in the ViewPortChanged event handler. In this way, you can see how the viewport is updated and find out why it is not updated as expected. You can set breakpoint and single-step the code if you need to examine the parameters in detail for each step.
Hope this can help.
Regards
Peter Kwan |
|