How to automatically scroll until a specific allocation is visible.

This example will cause the chart to scroll (vertically and/or horizontally as necessary) until the target allocation is visible in the displayed plot area.

Drop a timer ("ScrollTimer") onto the form, and set the interval to be a fairly small fraction of a second. You may need to experiment with the interval and the horizontal scroll fraction ("delta" in the code below) to see what works best for you.

procedure TForm1.ScrollTimerTimer(Sender: TObject);
  delta, s, e: TDateTime;
  r: integer;
  vert, horz: boolean;
  if Assigned(FTargetAllocation) then begin
      horz := true;
      s := RAC.StartAt;
      e := RAC.EndAt;
      delta := (e - s) / 30.0; // how much to scroll by
      if FTargetAllocation.StartAt < s then
        RAC.SetDateTime(s - delta, e - delta)
      else if FTargetAllocation.EndAt > e then
        RAC.SetDateTime(s + delta, e + delta)
        horz := false;

      vert := true;
      r := RAC.IndexOf(FTargetAllocation.Resource);
      if r < RAC.FirstDisplayedIndex then
        RAC.FirstDisplayedIndex := RAC.FirstDisplayedIndex - 1
      else if r > RAC.LastDisplayedIndex then
        RAC.FirstDisplayedIndex := RAC.FirstDisplayedIndex + 1
        vert := false;

      ScrollTimer.Enabled := horz or vert;
  end else
    ScrollTimer.Enabled := false;
The above code is started by setting the FTargetAllocation and enabling the ScrollTimer.
          // scroll to the first allocation of the first resource (if there is one)
          if (RAC.Count > 1) and (RAC.Resources[0].Count > 1) then begin
            FTargetAllocation := RAC.Resources[0].Allocations[0];
            ScrollTimer.Enabled := true;
What People Say

... The conclusion cannot be an other one than to state that if you are looking for a planning component you have to get the RAC. For your future planning business it is simply a must.
H. de Boer, Staaf Automatisering (see the full case study)
More …

No malware No spam
McAfee Site Report
Web of Trust