Hi,
What this means is that regardless of Zoom factor, Scrolled position, scales, etc. the Rectangle and DLine created will always be displayed at the same relative position as when they were created.
The hardest aspect is tring to figure out the ratiomatic relationship between the the Plotted Line X-Y scales and the X-Y coordants of the Retangle and DLine.
I believe I can calculate this using the formulas used in the TChart1.axis.Bottom.CalcPosPoint() and TChart1.axis.Left.CalcPosPoint() functions.
Can you provide me with these formulas?
Thanks!
Keeping Rectangle and DLine at a relative visual position
Re: Keeping Rectangle and DLine at a relative visual position
Hi,
Right, you'll probably have to transform pixel units to axes coordinates or vice-versa:
- CalcPosValue takes a Double (value in the axis) and returns an Integer (pixel position).
- CalcPosPoint takes an Integer (pixel position) and returns a Double (value in the axis).
However, I'm not sure to understand what tools are you using. I understand you have problems with both the "rectangle" and the "dline", but the DrawLine tool already zooms and scrolls following the axis, isn't it?
Maybe you are using a different tool.
Anyway, you'll probably have to save the position of the figures into global variables, force a chart repaint (Environment.InternalRepaint) at the OnZoom/OnUndoZoom/OnScroll events to let the chart update the internal values, and use that global variables to update the tool positions, transforming them with the according Calc* function, if needed.
Right, you'll probably have to transform pixel units to axes coordinates or vice-versa:
- CalcPosValue takes a Double (value in the axis) and returns an Integer (pixel position).
- CalcPosPoint takes an Integer (pixel position) and returns a Double (value in the axis).
However, I'm not sure to understand what tools are you using. I understand you have problems with both the "rectangle" and the "dline", but the DrawLine tool already zooms and scrolls following the axis, isn't it?
Code: Select all
TChart1.Aspect.View3D = False
TChart1.AddSeries scPoint
TChart1.Series(0).FillSampleValues
TChart1.Tools.Add tcRectangle
TChart1.Tools.Add tcDrawLine
With TChart1.Tools.Items(0).asRectangle
.AllowDrag = False
.AllowResize = False
' position in pixels
.Left = 100
.Top = 50
.Width = 200
.Height = 50
.Shape.Color = vbRed
End With
With TChart1.Series(0).YValues
ymed = .Minimum + (.Maximum - .Minimum) / 2
End With
With TChart1.Tools.Items(1).asDrawLine
.EnableDraw = False
.EnableSelect = False
' position in axis values
.AddLine 2, ymed - 20, 5, ymed + 20
End With
Anyway, you'll probably have to save the position of the figures into global variables, force a chart repaint (Environment.InternalRepaint) at the OnZoom/OnUndoZoom/OnScroll events to let the chart update the internal values, and use that global variables to update the tool positions, transforming them with the according Calc* function, if needed.
Best Regards,
Yeray Alonso Development & Support Steema Software Av. Montilivi 33, 17003 Girona, Catalonia (SP) | |
Please read our Bug Fixing Policy |
Re: Keeping Rectangle and DLine at a relative visual position
Thanks Yeray,
That's good!
However,
When you "Zoom" the visible length of the DLine increases and most likely extends beyond the panel boundries.
That's a problem.
I need to reduce the visible length of the DLine in such a way as to maintain the visible length (to about ~ 2 centimeters) regardless of the "Zoom" factor. And in doing so, I will have to re-calculate a new position of the rectangle in order to have the center of the bottom boundry attach to the end of the DLine.
I think the answers I'm looking for are contained in the following:
Yes, the DLine does follow the Axis, when you "Scroll" the visible length of the DLine does not change, and it remains connected to the plotted line.I understand you have problems with both the "rectangle" and the "dline", but the DrawLine tool already zooms and scrolls following the axis, isn't it?
That's good!
However,
When you "Zoom" the visible length of the DLine increases and most likely extends beyond the panel boundries.
That's a problem.
I need to reduce the visible length of the DLine in such a way as to maintain the visible length (to about ~ 2 centimeters) regardless of the "Zoom" factor. And in doing so, I will have to re-calculate a new position of the rectangle in order to have the center of the bottom boundry attach to the end of the DLine.
I think the answers I'm looking for are contained in the following:
I'll give these a try, and see if it works for me!Right, you'll probably have to transform pixel units to axes coordinates or vice-versa:
- CalcPosValue takes a Double (value in the axis) and returns an Integer (pixel position).
- CalcPosPoint takes an Integer (pixel position) and returns a Double (value in the axis).