How to add non-standard graphics to the chart.
This technique is very powerful and enables the addition of many non-standard elements to the chart. The key to this technique is to implement an OnDrawProgress event handler. This event is fired at various stages in the drawing process, and so allows additional graphics to be added at each stage. For example, you may want to add graphics on top of the plot background, but behind allocations and their shadows -- in this particular case, you'd draw your graphics when the "Progress" argument is equal to dpBackgroundDone. These are the values and meanings of the Progress argument.
| TssDrawProgress | Meaning |
|---|---|
| dpBeforeStart | Before any drawing has been done. Can be used as a reset. |
| dpFrameDone | The outer frame has been drawn. |
| dpBackgroundDone | The background has been drawn, including any alternating colour. |
| dpLabelsDone | The resource name and date/time labels have been drawn. This is the earliest point at which the TssResource.PlotRect is valid. |
| dpShadowsDone | The allocation shadows have been drawn. |
| dpAllocationsDone | The allocations have been drawn. |
| dpAllDone | All drawing is finished. |
Example 1
This first example draws a logo in the bottom-right corner of the chart area. The logo is drawn on top of the background and shadows, but underneath the allocations.

procedure TForm1.FormCreate(Sender: TObject); begin FLogo := TBitmap.Create; FLogo.Transparent := true; FLogo.TransparentMode := tmAuto; FLogo.LoadFromResourceName(HInstance, 'logo.bmp'); end; procedure TForm1.FormDestroy(Sender: TObject); begin FreeAndNil(FLogo); end; procedure TForm1.RACDrawProgress(Sender: TObject; Canvas: TCanvas; DrawRect: TRect; Progress: TssDrawProgress); begin if Progress = dpShadowsDone then begin // display our logo if Assigned(FLogo) then Canvas.Draw(RAC.PlotRect.Right - FLogo.Width - 10, RAC.PlotRect.Bottom - FLogo.Height - 10, FLogo); end; end;
Example 2
This second example draws a blue line at the current date and time.

procedure TForm1.RACDrawProgress(Sender: TObject; Canvas: TCanvas; DrawRect: TRect; Progress: TssDrawProgress); var x: integer; begin // indicate the current time with a vertical line if Progress = dpShadowsDone then begin x := RAC.DateTimeToX(Now); Canvas.Pen.Color := clBlue; Canvas.Pen.Width := 2; Canvas.MoveTo(x, DrawRect.Top); Canvas.LineTo(x, DrawRect.Bottom); end; end;
Note: This event handler can be invoked many times a second while the user is dragging the chart or an allocation. It is important that it completes quickly in order to maintain a responsive user experience.


