While preparing a new tutorial I came across a situation that a TFitSeries getting its data from a UserDefinedChartSource tries to redraw before the fit is performed. As a consequence, the DrawFuncHelper crashes becauses of the NaNs produced along the way.
A workaround would be to exit the Draw method if the fit had not yet beein performed or was not successful.
The new TFitSeries.Draw method, therefore, should be like this:
procedure TFitSeries.Draw(ADrawer: IChartDrawer);
var
de : TIntervalList;
begin
if IsEmpty or (not FValidFitParams) then exit; // wp: added FValidFitParams
ADrawer.Pen := Pen;
de := PrepareIntervals;
try
with TDrawFuncHelper.Create(Self, de, @Calculate, Step) do
try
DrawFunction(ADrawer);
finally
Free;
end;
finally
de.Free;
end;
end;