mirror of
https://gitlab.com/freepascal.org/lazarus/lazarus.git
synced 2026-01-06 04:20:31 +01:00
TAChart tutorial: Add source code for tutorial on TFuncSeries
git-svn-id: trunk@39215 -
This commit is contained in:
parent
8309b61dcb
commit
3184191f80
4
.gitattributes
vendored
4
.gitattributes
vendored
@ -3108,6 +3108,10 @@ components/tachart/test/SourcesTest.pas svneol=native#text/pascal
|
||||
components/tachart/test/UtilsTest.pas svneol=native#text/pascal
|
||||
components/tachart/test/test.lpi svneol=native#text/plain
|
||||
components/tachart/test/test.lpr svneol=native#text/pascal
|
||||
components/tachart/tutorials/func_series/func_series.lpi svneol=native#text/plain
|
||||
components/tachart/tutorials/func_series/func_series.lpr svneol=native#text/pascal
|
||||
components/tachart/tutorials/func_series/main.lfm svneol=native#text/plain
|
||||
components/tachart/tutorials/func_series/main.pas svneol=native#text/pascal
|
||||
components/tachart/tutorials/getting_started/getting_started.lpi svneol=native#text/plain
|
||||
components/tachart/tutorials/getting_started/getting_started.lpr svneol=native#text/pascal
|
||||
components/tachart/tutorials/getting_started/main.lfm svneol=native#text/plain
|
||||
|
||||
4
.gitignore
vendored
4
.gitignore
vendored
@ -254,6 +254,10 @@ components/tachart/test/lib
|
||||
components/tachart/tutorials/*.exe
|
||||
components/tachart/tutorials/*.lps
|
||||
components/tachart/tutorials/*.res
|
||||
components/tachart/tutorials/func_series/*.lps
|
||||
components/tachart/tutorials/func_series/*.res
|
||||
components/tachart/tutorials/func_series/backup
|
||||
components/tachart/tutorials/func_series/lib
|
||||
components/tachart/tutorials/getting_started/*.exe
|
||||
components/tachart/tutorials/getting_started/*.lps
|
||||
components/tachart/tutorials/getting_started/*.res
|
||||
|
||||
90
components/tachart/tutorials/func_series/func_series.lpi
Normal file
90
components/tachart/tutorials/func_series/func_series.lpi
Normal file
@ -0,0 +1,90 @@
|
||||
<?xml version="1.0"?>
|
||||
<CONFIG>
|
||||
<ProjectOptions>
|
||||
<Version Value="9"/>
|
||||
<PathDelim Value="\"/>
|
||||
<General>
|
||||
<SessionStorage Value="InProjectDir"/>
|
||||
<MainUnit Value="0"/>
|
||||
<Title Value="func_series"/>
|
||||
<ResourceType Value="res"/>
|
||||
<UseXPManifest Value="True"/>
|
||||
</General>
|
||||
<i18n>
|
||||
<EnableI18N LFM="False"/>
|
||||
</i18n>
|
||||
<VersionInfo>
|
||||
<StringTable ProductVersion=""/>
|
||||
</VersionInfo>
|
||||
<BuildModes Count="1">
|
||||
<Item1 Name="Default" Default="True"/>
|
||||
</BuildModes>
|
||||
<PublishOptions>
|
||||
<Version Value="2"/>
|
||||
<IncludeFileFilter Value="*.(pas|pp|inc|lfm|lpr|lrs|lpi|lpk|sh|xml)"/>
|
||||
<ExcludeFileFilter Value="*.(bak|ppu|o|so);*~;backup"/>
|
||||
</PublishOptions>
|
||||
<RunParams>
|
||||
<local>
|
||||
<FormatVersion Value="1"/>
|
||||
</local>
|
||||
</RunParams>
|
||||
<RequiredPackages Count="2">
|
||||
<Item1>
|
||||
<PackageName Value="TAChartLazarusPkg"/>
|
||||
</Item1>
|
||||
<Item2>
|
||||
<PackageName Value="LCL"/>
|
||||
</Item2>
|
||||
</RequiredPackages>
|
||||
<Units Count="2">
|
||||
<Unit0>
|
||||
<Filename Value="func_series.lpr"/>
|
||||
<IsPartOfProject Value="True"/>
|
||||
<UnitName Value="func_series"/>
|
||||
</Unit0>
|
||||
<Unit1>
|
||||
<Filename Value="main.pas"/>
|
||||
<IsPartOfProject Value="True"/>
|
||||
<ComponentName Value="Form1"/>
|
||||
<HasResources Value="True"/>
|
||||
<ResourceBaseClass Value="Form"/>
|
||||
<UnitName Value="main"/>
|
||||
</Unit1>
|
||||
</Units>
|
||||
</ProjectOptions>
|
||||
<CompilerOptions>
|
||||
<Version Value="11"/>
|
||||
<PathDelim Value="\"/>
|
||||
<SearchPaths>
|
||||
<IncludeFiles Value="$(ProjOutDir)"/>
|
||||
<UnitOutputDirectory Value="lib\$(TargetCPU)-$(TargetOS)"/>
|
||||
</SearchPaths>
|
||||
<Linking>
|
||||
<Options>
|
||||
<Win32>
|
||||
<GraphicApplication Value="True"/>
|
||||
</Win32>
|
||||
</Options>
|
||||
</Linking>
|
||||
<Other>
|
||||
<CompilerMessages>
|
||||
<MsgFileName Value=""/>
|
||||
</CompilerMessages>
|
||||
<CompilerPath Value="$(CompPath)"/>
|
||||
</Other>
|
||||
</CompilerOptions>
|
||||
<Debugging>
|
||||
<Exceptions Count="3">
|
||||
<Item1>
|
||||
<Name Value="EAbort"/>
|
||||
</Item1>
|
||||
<Item2>
|
||||
<Name Value="ECodetoolError"/>
|
||||
</Item2>
|
||||
<Item3>
|
||||
<Name Value="EFOpenError"/>
|
||||
</Item3>
|
||||
</Exceptions>
|
||||
</Debugging>
|
||||
</CONFIG>
|
||||
21
components/tachart/tutorials/func_series/func_series.lpr
Normal file
21
components/tachart/tutorials/func_series/func_series.lpr
Normal file
@ -0,0 +1,21 @@
|
||||
program func_series;
|
||||
|
||||
{$mode objfpc}{$H+}
|
||||
|
||||
uses
|
||||
{$IFDEF UNIX}{$IFDEF UseCThreads}
|
||||
cthreads,
|
||||
{$ENDIF}{$ENDIF}
|
||||
Interfaces, // this includes the LCL widgetset
|
||||
Forms, tachartlazaruspkg, main
|
||||
{ you can add units after this };
|
||||
|
||||
{$R *.res}
|
||||
|
||||
begin
|
||||
RequireDerivedFormResource := True;
|
||||
Application.Initialize;
|
||||
Application.CreateForm(TForm1, Form1);
|
||||
Application.Run;
|
||||
end.
|
||||
|
||||
76
components/tachart/tutorials/func_series/main.lfm
Normal file
76
components/tachart/tutorials/func_series/main.lfm
Normal file
@ -0,0 +1,76 @@
|
||||
object Form1: TForm1
|
||||
Left = 286
|
||||
Height = 250
|
||||
Top = 163
|
||||
Width = 400
|
||||
Caption = 'Form1'
|
||||
ClientHeight = 250
|
||||
ClientWidth = 400
|
||||
OnCreate = FormCreate
|
||||
LCLVersion = '1.0.1.3'
|
||||
object Chart1: TChart
|
||||
Left = 0
|
||||
Height = 250
|
||||
Top = 0
|
||||
Width = 400
|
||||
AxisList = <
|
||||
item
|
||||
Grid.Color = clSilver
|
||||
Minors = <>
|
||||
Title.LabelFont.Orientation = 900
|
||||
Title.LabelFont.Style = [fsBold]
|
||||
Title.Visible = True
|
||||
Title.Caption = 'y'
|
||||
end
|
||||
item
|
||||
Grid.Color = clSilver
|
||||
Alignment = calBottom
|
||||
Minors = <>
|
||||
Title.LabelFont.Style = [fsBold]
|
||||
Title.Visible = True
|
||||
Title.Caption = 'x'
|
||||
end>
|
||||
BackColor = clWhite
|
||||
Foot.Brush.Color = clBtnFace
|
||||
Foot.Font.Color = clBlue
|
||||
Title.Brush.Color = clBtnFace
|
||||
Title.Font.Color = clBlue
|
||||
Title.Text.Strings = (
|
||||
'TAChart'
|
||||
)
|
||||
OnAfterDrawBackWall = Chart1AfterDrawBackWall
|
||||
Align = alClient
|
||||
ParentColor = False
|
||||
object Chart1FuncSeries1: TFuncSeries
|
||||
Extent.UseXMax = True
|
||||
Extent.UseXMin = True
|
||||
Extent.UseYMax = True
|
||||
Extent.UseYMin = True
|
||||
Extent.XMax = 10
|
||||
Extent.XMin = -10
|
||||
Extent.YMax = 2
|
||||
Extent.YMin = -2
|
||||
Title = 'y = tan(x)'
|
||||
OnCalculate = Chart1FuncSeries1Calculate
|
||||
Pen.Color = clRed
|
||||
end
|
||||
object Chart1FuncSeries2: TFuncSeries
|
||||
Title = 'y =ln(x)'
|
||||
OnCalculate = Chart1FuncSeries2Calculate
|
||||
Pen.Color = clBlue
|
||||
end
|
||||
object Chart1ConstantLine1: TConstantLine
|
||||
Legend.Visible = False
|
||||
Arrow.BaseLength = 8
|
||||
Arrow.Visible = True
|
||||
Position = 0
|
||||
end
|
||||
object Chart1ConstantLine2: TConstantLine
|
||||
Legend.Visible = False
|
||||
Arrow.BaseLength = 8
|
||||
Arrow.Visible = True
|
||||
LineStyle = lsVertical
|
||||
Position = 0
|
||||
end
|
||||
end
|
||||
end
|
||||
89
components/tachart/tutorials/func_series/main.pas
Normal file
89
components/tachart/tutorials/func_series/main.pas
Normal file
@ -0,0 +1,89 @@
|
||||
unit main;
|
||||
|
||||
{$mode objfpc}{$H+}
|
||||
|
||||
interface
|
||||
|
||||
uses
|
||||
Classes, SysUtils, FileUtil, TAGraph, TAFuncSeries, TASeries, TATools, Forms,
|
||||
Controls, Graphics, Dialogs, Types;
|
||||
|
||||
type
|
||||
|
||||
{ TForm1 }
|
||||
|
||||
TForm1 = class(TForm)
|
||||
Chart1: TChart;
|
||||
Chart1ConstantLine1: TConstantLine;
|
||||
Chart1ConstantLine2: TConstantLine;
|
||||
Chart1FuncSeries1: TFuncSeries;
|
||||
Chart1FuncSeries2: TFuncSeries;
|
||||
procedure Chart1AfterDrawBackWall(ASender: TChart; ACanvas: TCanvas;
|
||||
const ARect: TRect);
|
||||
procedure Chart1FuncSeries1Calculate(const AX: Double; out AY: Double);
|
||||
procedure Chart1FuncSeries2Calculate(const AX: Double; out AY: Double);
|
||||
procedure FormCreate(Sender: TObject);
|
||||
private
|
||||
procedure UpdateDomainExclusions;
|
||||
end;
|
||||
|
||||
var
|
||||
Form1: TForm1;
|
||||
|
||||
implementation
|
||||
|
||||
{$R *.lfm}
|
||||
|
||||
uses
|
||||
Math, TAChartUtils;
|
||||
|
||||
{ TForm1 }
|
||||
|
||||
{ In the trunk version of Lazarus, you can use the event Chart.OnExtentChanging
|
||||
for updating the domain exclusions - its name is more intuitive... }
|
||||
procedure TForm1.Chart1AfterDrawBackWall(ASender: TChart; ACanvas: TCanvas;
|
||||
const ARect: TRect);
|
||||
begin
|
||||
Unused(ASender);
|
||||
Unused(ACanvas);
|
||||
Unused(ARect);
|
||||
UpdateDomainExclusions;
|
||||
end;
|
||||
|
||||
procedure TForm1.Chart1FuncSeries1Calculate(const AX: Double; out AY: Double);
|
||||
begin
|
||||
AY := tan(AX);
|
||||
end;
|
||||
|
||||
procedure TForm1.Chart1FuncSeries2Calculate(const AX: Double; out AY: Double);
|
||||
begin
|
||||
AY := ln(AX);
|
||||
end;
|
||||
|
||||
procedure TForm1.FormCreate(Sender: TObject);
|
||||
begin
|
||||
with Chart1FuncSeries2.DomainExclusions do begin
|
||||
AddRange(NegInfinity, 0.0);
|
||||
end;
|
||||
end;
|
||||
|
||||
procedure TForm1.UpdateDomainExclusions;
|
||||
var
|
||||
ex: TDoubleRect;
|
||||
x: Integer;
|
||||
begin
|
||||
ex := Chart1.CurrentExtent;
|
||||
Chart1.DisableRedrawing;
|
||||
try
|
||||
with Chart1FuncSeries1.DomainExclusions do begin
|
||||
Clear;
|
||||
for x := Floor(ex.a.x / Pi - 0.5) to Ceil(ex.b.x / Pi + 0.5) do
|
||||
AddPoint((x + 0.5) * Pi);
|
||||
end;
|
||||
finally
|
||||
Chart1.EnableRedrawing;
|
||||
end;
|
||||
end;
|
||||
|
||||
end.
|
||||
|
||||
Loading…
Reference in New Issue
Block a user