Keeping Rectangle and DLine at a relative visual position

TeeChart for ActiveX, COM and ASP
Post Reply
tirby
Newbie
Newbie
Posts: 84
Joined: Mon Mar 16, 2009 12:00 am

Keeping Rectangle and DLine at a relative visual position

Post by tirby » Fri May 24, 2013 2:48 pm

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!

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

Re: Keeping Rectangle and DLine at a relative visual position

Post by Yeray » Mon May 27, 2013 1:38 pm

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?

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
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.
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

tirby
Newbie
Newbie
Posts: 84
Joined: Mon Mar 16, 2009 12:00 am

Re: Keeping Rectangle and DLine at a relative visual position

Post by tirby » Tue May 28, 2013 2:11 pm

Thanks Yeray,
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?
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.
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:
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).
I'll give these a try, and see if it works for me!

Post Reply