Roadmap Tutorial API's: XYGraph Axes etc Series Stats
You can avoid duplication of data handling by asking one TxyGraph to hook a series that belongs to another TxyGraph. Thereafter any changes to the series will be changed in both graphs. While there is no limit to the number of xyGraphs that can hook a series, each graph can only hook a series once. (note that this doesn't actually avoid data duplication, but saves you having to maintain the duplication).
Hooking is initiated by the procedure
procedure Hookseries(Source:TSeries; Ahooktype:THooktype; Dest:Integer; WantPersist:boolean);
where THookType = (ht_PlotData {$IFDEF STATISTICS}, ht_PlotResiduals {$ENDIF});
ie. Xygraph2.hookseries(xygraph1[1], ht_PlotResiduals, 2, false);
will result in Xygraph2 series 2 showing the residuals, if any are available, of the regression for xygraph1 series 1. Want persist has the same function as in unhookseries, but is only used if the series is already hooked to another series. (i.e. if xygraph1[1] was already hooked to xgraph2[2]- that results in an implicit unhooking)
Hooking is ended by
procedure unhookseries(source:TSeries; WantPersist:boolean);
If Wantpersist is true the data will be kept, otherwise it will be deleted. You do not need to unhook a series before deleting the series, or the TxyGraph, or terminating the application.
While you don't need to unhook a hook manually, you should be aware that it is possible that the hook event will be called during the termination of your application, after the window handles have been destroyed. If you event code causes a repaint you should preface it with a
if not application.terminating then ....
property Hooks [o:tobject] :TDataChangeEvent;
the hooks property allows for objects to register an interest in the data of the series.. This allows other analytical tools to use the same TDataSeries.
create a hook like this:
xygraph1[1].Hooks[self] := Form1.OnSeriesChange
and terminate the connection like so:
xygraph1[1].Hooks[self] := nil;
self is an index object. (self is only used to make sure the right connection is terminated when the hook is set back to nil. Tobject(longint) would work just as well)
Each time anything happens to a series, it will notify existing hooks by calling the event. TDataChangeEvent is declared as:
TDataChangeEvent=procedure (Sender:TObject; TheMessage:TDSChangeType) of object;
where TheMessage identifies the reason for the call:
Warning:
Although any of the registered objects (or any other objects!) can add data, etc, I've got no idea whether that'll work. So be careful! xyGraph actually defines a descendent and uses requestpaint, but only one descendent can use the hooks.