Search code examples
delphiteechart

OnGetMarkText is not fired in TContourSeries


I have a TContourSeries with marks visible and want to display percentage values in a custom format. So I created a method GetMarkText and assigned it to the OnGetMarkText property. Lets assume it looks like this (simplified):

...
  serContourLines.OnGetMarkText := GetMarkText;
...

procedure TForm1.GetMarkText(Sender: TChartSeries;
  ValueIndex: Integer; var MarkText: string);
begin
  MarkText := MarkText + ' %';
end;

But the method never gets called. The marks on the contour lines are displayed fine, but the text is just the value coming from the data. It even regards the ValueFormat for the series. But it doesn't show the text as defined in the event method.

The code is marked as compiled (blue dots), but a break point in the method is never reached.


Solution

  • I'm copying the reply from here:

    The Contour Series is a bit special and it doesn't draw the marks as the other series. It internally calculates the levels and draws a mark for each level, instead of drawing a mark for each point. However, I believe it could use the OnGetMarkText event without problems so I've added it to the public tracker (#2253).

    Since you have the sources, could you please try to add this two lines of code into the TContourSeries.DrawAllValues.DrawLevelLines method in TeeSurfa.pas?

          if tmpDrawMarks then
          begin
            // Get mark text:
            case Marks.Style of
              smsSeriesTitle: tmpSt:=SeriesTitleOrName(Self);
               smsPointIndex: tmpSt:=IntToStr(TheLevel);
            else
              tmpSt:=FormatFloat(ValueFormat,UpToValue);
            end;
    
            if Assigned(OnGetMarkText) then  //Fix for #2253, Line 5429
               OnGetMarkText(Self,TheLevel,tmpSt);
    
            // Get mark size:
            CalculateMarkPosition(Marks,tmpSt,0,0,Position);
            tmpSize.X:=Position.Width;
            tmpSize.Y:=Position.Height;
          end;