Roadmap Tutorial API's: XYGraph Axes etc Series Stats
procedure DrawFunction(F: PlotFunction; var parms; x1, x2: Double; color: TColor; style: TPenStyle; steps: Word);
A convenient way to graph a function; automatically fills graph; handles singularities in the function.
F must be far params may be of any type (eg, array of Double); there are no type checks
The graph of the function will be drawn from x= min to x= max
if min=max they will be set to XAxis.Min and XAxis.Max
if min or max are outside the graph range, they will be clipped
to XAxis.Min, XAxis.Max
If steps=0, "enough" steps will be taken to smooth the graph
PlotFunction = function(x: Double; var parms): Double;
function Osc(t: Double; var params): Double; far; var AmpPer: array [0..1] of Double absolute params; begin Result := AmpPer[0]*sin(AmpPer[1]*t)/t; end
var AP:array [1..5] of Double;
XAxis.Min := 0; XAxis.Max := 10; AP[1] := 50; AP[2] := pi;
DrawFunction(Osc, AP, 0, 6*pi, clRed, psSolid, 50);
This will display the curve from 0 to 10. Note that the singularity at 0 will cause no difficulty, even if XAxis.Min is moved to a negative value. Also note that there is no type checking on parms.
The OnPaintEnd event exists to notify the program each time a succesful paint is completed. This is the right time to draw the function (particularly if you want the function to print).