Page 1 of 1

Relative placement of marks

Posted: Sat Jan 05, 2013 7:49 pm
by 16564537
Hi,

I have a chart with several Lines series. For each point on the series I wish to display a Mark, at a position relative (in pixels) to the point. After reading some suggestions on this forum, I have come to the following code which I place in the OnAfterDraw event.

Code: Select all

procedure TdlgSD_WellPlot.OnAfterDraw(Sender: TObject);
var
  APosition: TSeriesMarkPosition;
  ii, jj: Integer;
begin
  inherited;
  APosition := TSeriesMarkPosition.Create;
  try
    for ii := 0 to (Sender as TChart).SeriesList.Count - 1 do
    begin
      for jj := 0 to (Sender as TChart).Series[ii].ValuesList.Count - 1 do
      begin
        APosition.Custom := true;
        APosition.LeftTop.x := (Sender as TChart).Series[ii].CalcXPos(jj);
        APosition.LeftTop.y := (Sender as TChart).Series[ii].CalcYPos(jj);
        (Sender as TChart).Series[ii].Marks.Positions[jj] := APosition;
      end;
    end;
  finally
    APosition.Free;
  end;
end;
Using this code, the Marks do appear but remain "static" when panning or zooming the chart (i.e. don't move with the line series). Any suggestions to what I am doing wrong?

Thanks,
Mark

Re: Relative placement of marks

Posted: Mon Jan 07, 2013 9:25 am
by yeray
Hi Mark,

I see in the second "for" you are looping from 0 to the Series ValuesList.Count-1. Note this ValuesList contains the array of ValueLists: XValues, YValues. So ValuesList.Count = 2. Try changing the second "for" for this:

Code: Select all

for jj := 0 to (Sender as TChart).Series[ii].Count - 1 do