Code: Select all
Series.OnGetMarkText := SeriesGetMarkText;
Code: Select all
procedure TMyForm.SeriesGetMarkText(Sender: TChartSeries; ValueIndex: Integer; var MarkText: string);
var
LPosition: TSeriesMarkPosition;
XPos, YPos: Integer;
begin
inherited;
LPosition := Sender.Marks.Positions[ValueIndex];
if LPosition = nil then
begin
LPosition := TSeriesMarkPosition.Create;
LPosition.Custom := true;
end;
XPos := Sender.CalcXPos(ValueIndex);
YPos := Sender.CalcYPos(ValueIndex);
LPosition.LeftTop.X := XPos + LPosition.Width + 50; // Arbitrary shift for demo
LPosition.LeftTop.Y := YPos - LPosition.Height - 10;
Sender.Marks.Positions[ValueIndex] := LPosition;
end;
- At first pass, LPosition is never (!) assigned, so it must be created (if there is a non-empty label).
- When creating the TSeriesMarkPosition, its Width and Height are always initiated as 0 (i.e. not sized to MarkText)
- The code above leaks. ReportMemoryLeaksOnShutdown always reports exactly the number of TSeriesMarkPositions created (i.e. the number of points where label is a non-empty string).