Graph Annotation to move on zoom or scroll

TeeChart VCL for Borland/CodeGear/Embarcadero RAD Studio, Delphi and C++ Builder.
Post Reply
Nicho
Newbie
Newbie
Posts: 13
Joined: Mon Jul 09, 2007 12:00 am
Location: Adelaide Australia
Contact:

Graph Annotation to move on zoom or scroll

Post by Nicho » Mon Mar 07, 2011 5:46 am

Hello, I have to show comments near the selected points on TLine Series (data coming from database). I am using TAnnotationTool and position the annotation correctly on a graph, but after scrolling or zooming graph - all my annotations are not in sync with my points, so how can I stick them together (exactly as the mark). Thank you

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

Re: Graph Annotation to move on zoom or scroll

Post by Yeray » Mon Mar 07, 2011 10:47 am

Hi Nicho,

You have to recalculate the positions every time the chart is scrolled because the positions have changed.
Use the series CalcXPos and CalcYPos functions at OnScroll event to get the X and Y positions in pixels of each series point. And use these values to set Left and Top properties in the annotations.
If you still have problems with it, don't hesitate to let us know.
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

Nicho
Newbie
Newbie
Posts: 13
Joined: Mon Jul 09, 2007 12:00 am
Location: Adelaide Australia
Contact:

Re: Graph Annotation to move on zoom or scroll

Post by Nicho » Mon Mar 07, 2011 11:05 pm

Thank you

Nicho
Newbie
Newbie
Posts: 13
Joined: Mon Jul 09, 2007 12:00 am
Location: Adelaide Australia
Contact:

Re: Graph Annotation to move on zoom or scroll

Post by Nicho » Tue Mar 15, 2011 12:07 am

Is there any way to find an index of line series by XValue? Don't want to loop XValues, because it could be more then 10000 point
I created a dictionary of annotations as <XValue, TAnnotationTool>
now, to move all of them on zoom or scroll, I have to find out an index of each point, contains comments.
Cannot use an index as Key in a dictionary, because the user can add, remove points, so the only unchangeable part is XValue

Thank you

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

Re: Graph Annotation to move on zoom or scroll

Post by Yeray » Tue Mar 15, 2011 4:10 pm

Hi Nicho,

You could loop from FirstVisibleIndex to LastVisibleIndex if you know that the point you are looking for is visible, but I'm afraid the only way to find the index of a point for a given XValue is to loop into the data.
Of course, if there would be a direct association you could assume in your specific application, you could avoid this loop. For example, if you know that your XValues go from 0 to 9999, the indexes would coincide with the XValues. Or if you have DateTimes but you know that the increment is constant, you could calculate the index of a given datetime. But allowing the user to add and remove values would probably discard these direct associations.
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

Nicho
Newbie
Newbie
Posts: 13
Joined: Mon Jul 09, 2007 12:00 am
Location: Adelaide Australia
Contact:

Re: Graph Annotation to move on zoom or scroll

Post by Nicho » Tue Mar 15, 2011 10:04 pm

I found another way: Series1.XValues.Locate(XValue)

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

Re: Graph Annotation to move on zoom or scroll

Post by Yeray » Wed Mar 16, 2011 8:14 am

Hi Nicho,

Yes, there is a Locate function. But note it's looping:

Code: Select all

Function TChartValueList.Locate(Const AValue:TChartValue; FirstIndex,LastIndex:Integer):Integer;
begin
  for result:=FirstIndex to LastIndex do
      if Value[result]=AValue then Exit;
  result:=-1;
end;

Function TChartValueList.Locate(Const AValue:TChartValue):Integer;
Begin
  result:=Locate(AValue,0,Count-1);
end;
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

Post Reply