1 unit main; 2 3 {$mode objfpc}{$H+} 4 5 interface 6 7 uses 8 Classes, SysUtils, FileUtil, TAGraph, TAFuncSeries, TASeries, TATools, Forms, 9 Controls, Graphics, Dialogs, Types; 10 11 type 12 13 { TForm1 } 14 15 TForm1 = class(TForm) 16 Chart1: TChart; 17 Chart1ConstantLine1: TConstantLine; 18 Chart1ConstantLine2: TConstantLine; 19 Chart1FuncSeries1: TFuncSeries; 20 Chart1FuncSeries2: TFuncSeries; 21 procedure Chart1AfterDrawBackWall(ASender: TChart; ACanvas: TCanvas; 22 const ARect: TRect); 23 procedure Chart1FuncSeries1Calculate(const AX: Double; out AY: Double); 24 procedure Chart1FuncSeries2Calculate(const AX: Double; out AY: Double); 25 procedure FormCreate(Sender: TObject); 26 private 27 procedure UpdateDomainExclusions; 28 end; 29 30 var 31 Form1: TForm1; 32 33 implementation 34 35 {$R *.lfm} 36 37 uses 38 Math, TAChartUtils; 39 40 { TForm1 } 41 42 { In the trunk version of Lazarus, you can use the event Chart.OnExtentChanging 43 for updating the domain exclusions - its name is more intuitive... } 44 procedure TForm1.Chart1AfterDrawBackWall(ASender: TChart; ACanvas: TCanvas; 45 const ARect: TRect); 46 begin 47 Unused(ASender); 48 Unused(ACanvas); 49 Unused(ARect); 50 UpdateDomainExclusions; 51 end; 52 53 procedure TForm1.Chart1FuncSeries1Calculate(const AX: Double; out AY: Double); 54 begin 55 AY := tan(AX); 56 end; 57 58 procedure TForm1.Chart1FuncSeries2Calculate(const AX: Double; out AY: Double); 59 begin 60 AY := ln(AX); 61 end; 62 63 procedure TForm1.FormCreate(Sender: TObject); 64 begin 65 with Chart1FuncSeries2.DomainExclusions do begin 66 AddRange(NegInfinity, 0.0); 67 end; 68 end; 69 70 procedure TForm1.UpdateDomainExclusions; 71 var 72 ex: TDoubleRect; 73 x: Integer; 74 begin 75 ex := Chart1.CurrentExtent; 76 Chart1.DisableRedrawing; 77 try 78 with Chart1FuncSeries1.DomainExclusions do begin 79 Clear; 80 for x := Floor(ex.a.x / Pi - 0.5) to Ceil(ex.b.x / Pi + 0.5) do 81 AddPoint((x + 0.5) * Pi); 82 end; 83 finally 84 Chart1.EnableRedrawing; 85 end; 86 end; 87 88 end. 89 90