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); var delta, s, e: TDateTime; r: integer; vert, horz: boolean; begin if Assigned(FTargetAllocation) then begin RAC.BeginUpdate; try 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) else 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 else vert := false; ScrollTimer.Enabled := horz or vert; finally RAC.EndUpdate; end; end else ScrollTimer.Enabled := false; end;The above code is started by setting the FTargetAllocation and enabling the ScrollTimer.
begin // scroll to the first allocation of the first resource (if there is one) if (RAC.Count > 1) and (RAC.Resources.Count > 1) then begin FTargetAllocation := RAC.Resources.Allocations; ScrollTimer.Enabled := true; end; end;
- Screen Shots
- FAQ & Getting Started
- User Comments
- Support Forum
- Change History
|What People Say|
This is a great component. I've been using it for a year. It's well written, performance is top notch, and the couple of time I've asked for support, I've gotten it right away from the author.