1

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?

LU RD
  • 34,438
  • 5
  • 88
  • 296

1 Answers1

1

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;
LU RD
  • 34,438
  • 5
  • 88
  • 296
  • Thank you. SeriesMarks is what I was looking for. Its working, except that all of the points on the series have marks with their y values. How do I prevent this? – user1254689 Mar 26 '12 at 06:39
  • If I set all marks to "" then the y value still appears. Here is my code: SeriesMarks sMarks_Chart1_Line2 = new SeriesMarks(Chart1_Line2); sMarks_Chart1_Line2.setVisible(true); sMarks_Chart1_Line2.getPen().setColor(Color.RED); Chart1_Line2.setMarks(sMarks_Chart1_Line2); Chart1_Line2.getMarks().setVisible(true); Chart1_Line2.add(new com.steema.teechart.DateTime(new DateTime(tsDateTime).getMillis()), dStart_value, ""); – user1254689 Mar 26 '12 at 07:04
  • Hmm, try activating the `OnGetMarkText` instead. The latest documentation for TeeChart (in XE2) says : "This event notifies the user that a Mark Text String must be supplied. MarkText string contains the default text representation. You can alter MarkText for the Series to paint a customized mark, or set it to empty to hide the specific mark." – LU RD Mar 26 '12 at 07:09
  • @user1254689 you may need to set Marks.Style as well, for example: Series1.Marks.Style:=smsLabel – Narcís Calvet Mar 26 '12 at 08:52
  • I am completely stumped. How do I access OnGetMarkText in Java? If its through addSeriesPaintListener; how do I identify this event? – user1254689 Mar 26 '12 at 09:30
  • Ok, not your fault, the question is tagged with Delphi. I think @NarcísCalvet may provide some more help since my Java knowledge for TeeChart is limited. – LU RD Mar 26 '12 at 11:37
  • 2
    Hello, Find an example of MarkTextResolver's usage here: http://www.teechart.net/support/viewtopic.php?f=10&t=6757&start=0 – Yeray Mar 27 '12 at 14:27