I am using Annotation and AnnotationCallout to create labels on a series. But the problem I have is that their positions are not updating as new data is added to the chart. The series scrolls, but the Annotation / AnnotationCallout stay in the same place.
I set the Annotation and AnnotationCallout with the following code:
Anno.setLeft(aSeries.calcXPos(iIndex)-51);
Anno.setTop(aSeries.calcYPos(iIndex)+100);
Callout.setXPosition(aSeries.calcXPos(iIndex));
Callout.setYPosition(aSeries.calcYPos(iIndex));
Is there a way to attach them to point on a series or am I using the wrong tool for the job?
Annotations are positioned either on pixel positions or relative positions on the chart depending on how you define the Scaling
property.
That's how Annotation
works. So once you have defined the position of the annotation it sticks there.
If you want labels sticked on the points, look at Series.Marks
.
When you add points to the series you can add a label text like:
AddXY(xPos,yPos,'Hello',clGreen);
Set Series.Marks.Visible := True
to show the mark labels. To customize the label text on the fly, look at the event TChartSeries.OnGetMarkText
.
Explore all Series.Marks
properties to customize the look to your preference.
Update :
In order to hide some marks on your series data, set the label text to empty string during the OnGetMarkText
event.
An example how to use OnGetMarkText
:
...
Series1.OnGetMarkText := Self.Series1GetMarkText; // Define the OnGetMarkText event
...
procedure TMyForm.Series1GetMarkText(Sender: TChartSeries;
ValueIndex: Integer; var MarkText: string);
begin
if ValueIndex=3 then // Just an example how to set the selection criteria
MarkText := 'Hello'
else
MarkText := '';
end;