TAChart: Dynamic function series? lazarus / 55-TAChart ---------------------------------------------------------------------- ironphil · 2011-09-15 11:41 It is possible to create function series at runtime? I want to modelize peaks with gaussians but the number of peaks can change. Right now I use line series that I create at runtime and store in a dynamic array. It works well but I end up with polylines instead of function series. I understand how function series work but if I create them at runtime, how do I declare the function to calculate Y values from X values? The series will use the same function (gaussian curve), only the parameters will change (centre, width, height) so I need a way to provide different parameters to the calculate function. ---------------------------------------------------------------------- Ask · 2011-09-15 13:41 Code: [Select]fs := TFuncSeries.Create(Chart1); fs.OnCalculate := @MyFunc; Chart1.AddSeries(fs); where MyFunc is your function. It is of course free to use any variables you need. ---------------------------------------------------------------------- ironphil · 2011-09-15 15:05 Thank you, that's exactly what I needed. ---------------------------------------------------------------------- 1660 · 2013-11-05 18:48 Hi, Can someone pls give an example of "@Myfunc" =) Quote from: Ask on September 15, 2011, 03:41:00 pmCode: [Select]fs := TFuncSeries.Create(Chart1); fs.OnCalculate := @MyFunc; Chart1.AddSeries(fs); where MyFunc is your function. It is of course free to use any variables you need. ---------------------------------------------------------------------- wp · 2013-11-05 19:47 Suppose you want to plot the sine function. Then you implement this procedure as a method of any object, typically the form on which the chart resides: Code: [Select]procedure TForm1.MyFunc(const AX: Double; out AY: Double); begin   AY := sin(AX); end; In addition you may have a look at the tutorial http://wiki.lazarus.freepascal.org/TAChart_Tutorial:_Function_Series. ---------------------------------------------------------------------- 1660 · 2013-11-06 08:16 Sry, but i really dont get it  Code: [Select]implementation {$R *.lfm} { TForm1 }       procedure TForm1.Button1Click(Sender: TObject); var   fs: Tfuncseries; begin   fs := TFuncseries.Create(Chart1);   fs.OnCalculate := ???   Chart1.Addseries(fs); end; procedure TForm1.MyFunc(const AX: double; out AY: double); begin   AY := sin(AX); end;  I already know this tutorial, but it doesnt solve my problem. ---------------------------------------------------------------------- wp · 2013-11-06 08:22 You have to assign the address of the user-provided method "MyFunc" to the OnCalculate handler of the series, just as in a few postings above: Code: [Select]  fs.OnCalculate := @MyFunc; ---------------------------------------------------------------------- 1660 · 2013-11-06 08:52 Ah, thank you =)