TAChart: lack of initialization in TFitSeries.EquationText
Original Reporter info from Mantis: Marcin Wiazowski
-
Reporter name:
Original Reporter info from Mantis: Marcin Wiazowski
- Reporter name:
Description:
In the attached Reproduce application, there is a chart having TFitSeries. There are also two event handlers, containing same code:
procedure TForm1.FormCreate(Sender: TObject);
begin
Caption := Chart1FitSeries.EquationText.Get;
end;
procedure TForm1.ButtonTestClick(Sender: TObject);
begin
Caption := Chart1FitSeries.EquationText.Get;
end;
TFitSeries calculates its interpolation parameters, so the interpolated equation can be obtained (as a string) by calling EquationText.Get(): in case of the Reproduce application, the string will be:
'y = -0,125 + 1,025*x + 0,125*x^2'
The problem is that, after the Reproduce application is launched, window's caption is empty. After pressing the "Test" button - which executes same code as FormCreate() - window's caption is properly set.
This is because interpolation parameters are initialized in a TFitSeries.ExecFit() method, which is called in various places - in particular in TFitSeries.Draw(). So drawing the chart makes the parameters initialized - so pressing the "Test" button makes the "EquationText.Get" call succeeded. On the contrary, in the FormCreate() handler, interpolation parameters are not yet initialized - so the "EquationText.Get" call returns an empty string.
A solution is trivial: a call to "ExecFit()" should be also added to the TFitSeries.EquationText() method. The attached patch solves the problem. After applying the patch and launching the Reproduce application, window's caption shows the proper equation string from the beginning - there is no need to use the "Test" button.
Mantis conversion info:
- Mantis ID: 35163
- Build: 60526
- Version: 2.1 (SVN)
- Target version: 2.2