Page 1 of 1

Graph Annotation to move on zoom or scroll

Posted: Mon Mar 07, 2011 5:46 am
by 10046016
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

Re: Graph Annotation to move on zoom or scroll

Posted: Mon Mar 07, 2011 10:47 am
by yeray
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.

Re: Graph Annotation to move on zoom or scroll

Posted: Mon Mar 07, 2011 11:05 pm
by 10046016
Thank you

Re: Graph Annotation to move on zoom or scroll

Posted: Tue Mar 15, 2011 12:07 am
by 10046016
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

Re: Graph Annotation to move on zoom or scroll

Posted: Tue Mar 15, 2011 4:10 pm
by yeray
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.

Re: Graph Annotation to move on zoom or scroll

Posted: Tue Mar 15, 2011 10:04 pm
by 10046016
I found another way: Series1.XValues.Locate(XValue)

Re: Graph Annotation to move on zoom or scroll

Posted: Wed Mar 16, 2011 8:14 am
by yeray
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;