TAChart: Split individual demos in "axistransf" and "chartsource" demo projects off into separate frames.

This commit is contained in:
wp_xyz 2025-03-07 11:15:55 +01:00
parent 5b22d571b2
commit a07324e56d
26 changed files with 2147 additions and 1703 deletions

View File

@ -50,7 +50,7 @@
<PackageName Value="LCL"/>
</Item3>
</RequiredPackages>
<Units Count="2">
<Units Count="7">
<Unit0>
<Filename Value="axistransfdemo.lpr"/>
<IsPartOfProject Value="True"/>
@ -58,11 +58,51 @@
<Unit1>
<Filename Value="main.pas"/>
<IsPartOfProject Value="True"/>
<ComponentName Value="Form1"/>
<ComponentName Value="MainForm"/>
<HasResources Value="True"/>
<ResourceBaseClass Value="Form"/>
<UnitName Value="Main"/>
</Unit1>
<Unit2>
<Filename Value="frmlinear.pas"/>
<IsPartOfProject Value="True"/>
<ComponentName Value="LinearFrame"/>
<HasResources Value="True"/>
<ResourceBaseClass Value="Frame"/>
<UnitName Value="frmLinear"/>
</Unit2>
<Unit3>
<Filename Value="frmuser.pas"/>
<IsPartOfProject Value="True"/>
<ComponentName Value="UserFrame"/>
<HasResources Value="True"/>
<ResourceBaseClass Value="Frame"/>
<UnitName Value="frmUser"/>
</Unit3>
<Unit4>
<Filename Value="frmnormdistr.pas"/>
<IsPartOfProject Value="True"/>
<ComponentName Value="NormDistrFrame"/>
<HasResources Value="True"/>
<ResourceBaseClass Value="Frame"/>
<UnitName Value="frmNormDistr"/>
</Unit4>
<Unit5>
<Filename Value="frmlogarithm.pas"/>
<IsPartOfProject Value="True"/>
<ComponentName Value="LogarithmFrame"/>
<HasResources Value="True"/>
<ResourceBaseClass Value="Frame"/>
<UnitName Value="frmLogarithm"/>
</Unit5>
<Unit6>
<Filename Value="frmindependent.pas"/>
<IsPartOfProject Value="True"/>
<ComponentName Value="IndependentScaleFrame"/>
<HasResources Value="True"/>
<ResourceBaseClass Value="Frame"/>
<UnitName Value="frmIndependent"/>
</Unit6>
</Units>
</ProjectOptions>
<CompilerOptions>
@ -72,11 +112,6 @@
<IncludeFiles Value="$(ProjOutDir)"/>
<UnitOutputDirectory Value="lib\$(TargetCPU)-$(TargetOS)"/>
</SearchPaths>
<Parsing>
<SyntaxOptions>
<UseAnsiStrings Value="False"/>
</SyntaxOptions>
</Parsing>
<CodeGeneration>
<SmartLinkUnit Value="True"/>
</CodeGeneration>

View File

@ -7,15 +7,15 @@ uses
cthreads,
{$ENDIF}{$ENDIF}
Interfaces, // this includes the LCL widgetset
Forms, Main, TAChartLazarusPkg;
Forms, Main;
{$R *.res}
begin
Application.Scaled:=True;
Application.Title:='TAChart axis transformation demo';
Application.Scaled := True;
Application.Title := 'TAChart axis transformation demo';
Application.Initialize;
Application.CreateForm(TForm1, Form1);
Application.CreateForm(TMainForm, MainForm);
Application.Run;
end.

View File

@ -0,0 +1,191 @@
object IndependentScaleFrame: TIndependentScaleFrame
Left = 0
Height = 327
Top = 0
Width = 568
ClientHeight = 327
ClientWidth = 568
TabOrder = 0
DesignLeft = 540
DesignTop = 292
object Chart: TChart
Left = 0
Height = 268
Top = 0
Width = 568
AxisList = <
item
Grid.Visible = False
Intervals.Tolerance = 1
TickColor = clNavy
Marks.LabelFont.Color = clNavy
Marks.LabelFont.Style = [fsBold]
Marks.LabelBrush.Style = bsClear
Minors = <>
Title.LabelFont.Orientation = 900
Title.LabelBrush.Style = bsClear
Transformations = catIndependent1
end
item
Grid.Visible = False
Alignment = calBottom
Marks.Visible = False
Marks.LabelBrush.Style = bsClear
Minors = <>
Title.LabelBrush.Style = bsClear
end
item
Grid.Visible = False
Intervals.Tolerance = 1
TickColor = clGreen
Alignment = calRight
Marks.LabelFont.Color = clGreen
Marks.LabelFont.Style = [fsBold]
Marks.LabelBrush.Style = bsClear
Minors = <>
Title.LabelBrush.Style = bsClear
Transformations = catIndependent2
end>
Foot.Brush.Color = clBtnFace
Foot.Font.Color = clBlue
Title.Brush.Color = clBtnFace
Title.Font.Color = clBlue
Title.Text.Strings = (
'TAChart'
)
Align = alClient
Color = clWhite
object ChartLineSeries1: TLineSeries
AxisIndexY = 0
LinePen.Color = clNavy
LinePen.Width = 2
end
object ChartLineSeries2: TLineSeries
AxisIndexY = 2
LinePen.Color = clGreen
LinePen.Width = 2
end
end
object pnlIndependentControls: TPanel
Left = 4
Height = 51
Top = 272
Width = 560
Align = alBottom
AutoSize = True
BorderSpacing.Around = 4
BevelOuter = bvNone
ClientHeight = 51
ClientWidth = 560
TabOrder = 1
object fseScale1: TFloatSpinEdit
AnchorSideLeft.Control = lblScale1
AnchorSideLeft.Side = asrBottom
AnchorSideTop.Control = rgSyncAxisMarks
AnchorSideTop.Side = asrCenter
Left = 63
Height = 23
Top = 14
Width = 70
Alignment = taRightJustify
BorderSpacing.Left = 8
Increment = 0.1
MaxValue = 10
MinValue = 0.1
TabOrder = 0
Value = 1
OnChange = fseScale1Change
end
object fseScale2: TFloatSpinEdit
AnchorSideLeft.Control = lblScale2
AnchorSideLeft.Side = asrBottom
AnchorSideTop.Control = rgSyncAxisMarks
AnchorSideTop.Side = asrCenter
Left = 196
Height = 23
Top = 14
Width = 70
Alignment = taRightJustify
BorderSpacing.Left = 8
Increment = 0.1
MaxValue = 10
MinValue = 0.1
TabOrder = 1
Value = 1
OnChange = fseScale2Change
end
object lblScale1: TLabel
AnchorSideLeft.Control = pnlIndependentControls
AnchorSideTop.Control = fseScale1
AnchorSideTop.Side = asrCenter
Left = 16
Height = 15
Top = 18
Width = 39
BorderSpacing.Left = 16
Caption = 'Scale 1'
Font.Color = clNavy
Font.Style = [fsBold]
ParentFont = False
end
object lblScale2: TLabel
AnchorSideLeft.Control = fseScale1
AnchorSideLeft.Side = asrBottom
AnchorSideTop.Control = fseScale2
AnchorSideTop.Side = asrCenter
Left = 149
Height = 15
Top = 18
Width = 39
BorderSpacing.Left = 16
Caption = 'Scale 2'
Font.Color = clGreen
Font.Style = [fsBold]
ParentFont = False
end
object rgSyncAxisMarks: TRadioGroup
AnchorSideRight.Side = asrBottom
Left = 373
Height = 51
Top = 0
Width = 187
Align = alRight
AutoFill = True
AutoSize = True
BorderSpacing.InnerBorder = 4
Caption = ' Synchronize marks '
ChildSizing.LeftRightSpacing = 12
ChildSizing.TopBottomSpacing = 2
ChildSizing.HorizontalSpacing = 10
ChildSizing.EnlargeHorizontal = crsHomogenousChildResize
ChildSizing.EnlargeVertical = crsHomogenousChildResize
ChildSizing.ShrinkHorizontal = crsScaleChilds
ChildSizing.ShrinkVertical = crsScaleChilds
ChildSizing.Layout = cclLeftToRightThenTopToBottom
ChildSizing.ControlsPerLine = 3
ClientHeight = 31
ClientWidth = 183
Columns = 3
ItemIndex = 1
Items.Strings = (
'Left'
'None'
'Right'
)
TabOrder = 2
OnClick = rgSyncAxisMarksClick
end
end
object catIndependent1: TChartAxisTransformations
Left = 232
Top = 72
object catIndependent1Zoom: TLinearAxisTransform
end
end
object catIndependent2: TChartAxisTransformations
Left = 232
Top = 132
object catIndependent2Zoom: TLinearAxisTransform
end
end
end

View File

@ -0,0 +1,101 @@
unit frmIndependent;
{$mode ObjFPC}{$H+}
interface
uses
SysUtils, Classes,
Forms, Controls, StdCtrls, ExtCtrls, Spin,
TAGraph, TAChartAxis, TAChartAxisUtils, TACustomSource, TAAxisSource,
TASeries, TATransformations;
type
TIndependentScaleFrame = class(TFrame)
catIndependent1: TChartAxisTransformations;
catIndependent1Zoom: TLinearAxisTransform;
catIndependent2: TChartAxisTransformations;
catIndependent2Zoom: TLinearAxisTransform;
Chart: TChart;
ChartLineSeries1: TLineSeries;
ChartLineSeries2: TLineSeries;
fseScale1: TFloatSpinEdit;
fseScale2: TFloatSpinEdit;
lblScale1: TLabel;
lblScale2: TLabel;
pnlIndependentControls: TPanel;
rgSyncAxisMarks: TRadioGroup;
procedure fseScale1Change(Sender: TObject);
procedure fseScale2Change(Sender: TObject);
procedure rgSyncAxisMarksClick(Sender: TObject);
private
FAxisSource: TCustomAxisChartSource;
procedure FillIndependentSource;
public
constructor Create(AOwner: TComponent); override;
end;
implementation
{$R *.lfm}
constructor TIndependentScaleFrame.Create(AOwner: TComponent);
begin
inherited;
FillIndependentSource;
FAxisSource := TCustomAxisChartSource.Create(Self);
end;
procedure TIndependentScaleFrame.FillIndependentSource;
var
i: Integer;
v1, v2: Double;
begin
RandSeed := 923875;
v1 := 0;
v2 := 0;
for i := 1 to 100 do begin
v1 += Random - 0.48;
v2 += Random - 0.52;
ChartLineSeries1.AddXY(i, v1);
ChartLineSeries2.AddXY(i, v2);
end;
end;
procedure TIndependentScaleFrame.fseScale1Change(Sender: TObject);
begin
catIndependent1Zoom.Scale := fseScale1.Value;
end;
procedure TIndependentScaleFrame.fseScale2Change(Sender: TObject);
begin
catIndependent2Zoom.Scale := fseScale2.Value;
end;
procedure TIndependentScaleFrame.rgSyncAxisMarksClick(Sender: TObject);
var
la, ra: TChartAxis;
begin
la := Chart.LeftAxis;
ra := Chart.AxisList.GetAxisByAlign(calRight);
la.Marks.Source := nil;
ra.Marks.Source := nil;
case rgSyncAxisMarks.ItemIndex of
0: begin
FAxisSource.AxisFrom := ra;
FAxisSource.AxisTo := la;
la.Marks.Source := FAxisSource;
end;
2: begin
FAxisSource.AxisFrom := la;
FAxisSource.AxisTo := ra;
ra.Marks.Source := FAxisSource;
end;
end;
la.Grid.Visible := rgSyncAxisMarks.ItemIndex <> 1;
end;
end.

View File

@ -0,0 +1,154 @@
object LinearFrame: TLinearFrame
Left = 0
Height = 378
Top = 0
Width = 531
ClientHeight = 378
ClientWidth = 531
TabOrder = 0
DesignLeft = 515
DesignTop = 287
object Chart: TChart
Left = 0
Height = 343
Top = 0
Width = 531
AxisList = <
item
Grid.Visible = False
TickColor = clRed
AxisPen.Color = clRed
AxisPen.Visible = True
Marks.LabelFont.Color = clRed
Marks.AtDataOnly = True
Marks.LabelBrush.Style = bsClear
Minors = <>
Title.LabelFont.Color = clRed
Title.LabelFont.Orientation = 900
Title.Visible = True
Title.Caption = 'Summer temperature, °C'
Title.LabelBrush.Style = bsClear
Transformations = catTAuto
end
item
Intervals.MaxLength = 100
Intervals.MinLength = 20
Alignment = calBottom
Marks.LabelBrush.Style = bsClear
Minors = <>
Title.Visible = True
Title.Caption = 'Year'
Title.LabelBrush.Style = bsClear
end
item
Grid.Visible = False
TickColor = clBlue
Alignment = calRight
AxisPen.Color = clBlue
AxisPen.Visible = True
Marks.Distance = 4
Marks.LabelFont.Color = clBlue
Marks.AtDataOnly = True
Marks.LabelBrush.Style = bsClear
Minors = <>
Title.LabelFont.Color = clBlue
Title.LabelFont.Orientation = 900
Title.Visible = True
Title.Caption = 'Winter temperature, °F'
Title.LabelBrush.Style = bsClear
Transformations = catT
end>
Foot.Brush.Color = clBtnFace
Foot.Font.Color = clBlue
Frame.Visible = False
Title.Brush.Color = clBtnFace
Title.Font.Color = clBlue
Title.Text.Strings = (
'TAChart'
)
Align = alClient
Color = clWindow
object ChartSummer: TLineSeries
AxisIndexY = 0
LinePen.Color = clRed
LinePen.Width = 2
Source = rcsTSummer
end
object ChartWinterLine: TLineSeries
AxisIndexY = 2
LinePen.Color = clBlue
LinePen.Width = 2
Source = rcsTWinter
end
object ChartWinterBar: TBarSeries
AxisIndexY = 2
BarBrush.Color = clBlue
BarBrush.Style = bsDiagCross
Source = rcsTWinter
end
end
object pnlAutoControls: TPanel
Left = 0
Height = 35
Top = 343
Width = 531
Align = alBottom
AutoSize = True
BevelOuter = bvNone
ClientHeight = 35
ClientWidth = 531
TabOrder = 1
object cbAuto: TCheckBox
AnchorSideLeft.Control = pnlAutoControls
AnchorSideTop.Control = pnlAutoControls
AnchorSideTop.Side = asrCenter
Left = 8
Height = 19
Top = 8
Width = 73
BorderSpacing.Left = 8
BorderSpacing.Top = 8
BorderSpacing.Bottom = 8
Caption = 'Auto scale'
TabOrder = 0
OnChange = cbAutoChange
end
end
object rcsTSummer: TRandomChartSource
PointsNumber = 20
RandSeed = 114536250
XMax = 2009
XMin = 1990
YMax = 25
Left = 72
Top = 16
end
object rcsTWinter: TRandomChartSource
PointsNumber = 20
RandSeed = 23453245
XMax = 2009
XMin = 1990
YMax = 20
YMin = -15
Left = 344
Top = 224
end
object catTAuto: TChartAxisTransformations
Left = 144
Top = 16
object catTAutoAutoScaleAxisTransform1: TAutoScaleAxisTransform
Enabled = False
end
end
object catT: TChartAxisTransformations
Left = 416
Top = 224
object catTFahrToCel: TLinearAxisTransform
Offset = -17.777777777
Scale = 0.5555555555
end
object catTAutoScaleAxisTransform1: TAutoScaleAxisTransform
Enabled = False
end
end
end

View File

@ -0,0 +1,45 @@
unit frmLinear;
{$mode ObjFPC}{$H+}
interface
uses
SysUtils, Classes,
Forms, Controls, StdCtrls, ExtCtrls,
TAGraph, TASeries, TASources, TATransformations;
type
TLinearFrame = class(TFrame)
catT: TChartAxisTransformations;
catTAuto: TChartAxisTransformations;
catTAutoAutoScaleAxisTransform1: TAutoScaleAxisTransform;
catTAutoScaleAxisTransform1: TAutoScaleAxisTransform;
catTFahrToCel: TLinearAxisTransform;
cbAuto: TCheckBox;
Chart: TChart;
ChartSummer: TLineSeries;
ChartWinterBar: TBarSeries;
ChartWinterLine: TLineSeries;
pnlAutoControls: TPanel;
rcsTSummer: TRandomChartSource;
rcsTWinter: TRandomChartSource;
procedure cbAutoChange(Sender: TObject);
private
public
end;
implementation
{$R *.lfm}
procedure TLinearFrame.cbAutoChange(Sender: TObject);
begin
catTAutoAutoScaleAxisTransform1.Enabled := cbAuto.Checked;
catTAutoScaleAxisTransform1.Enabled := cbAuto.Checked;
end;
end.

View File

@ -0,0 +1,167 @@
object LogarithmFrame: TLogarithmFrame
Left = 0
Height = 322
Top = 0
Width = 480
ClientHeight = 322
ClientWidth = 480
TabOrder = 0
DesignLeft = 475
DesignTop = 165
object pnlLogControls: TPanel
Left = 8
Height = 23
Top = 291
Width = 464
Align = alBottom
AutoSize = True
BorderSpacing.Around = 8
BevelOuter = bvNone
ClientHeight = 23
ClientWidth = 464
TabOrder = 0
object cbLog: TCheckBox
AnchorSideLeft.Control = pnlLogControls
AnchorSideTop.Control = seTolerance
AnchorSideTop.Side = asrCenter
Left = 0
Height = 19
Top = 2
Width = 67
Caption = 'Log scale'
Checked = True
State = cbChecked
TabOrder = 0
OnChange = cbLogChange
end
object seTolerance: TSpinEdit
AnchorSideLeft.Control = lblTolerance
AnchorSideLeft.Side = asrBottom
AnchorSideTop.Control = pnlLogControls
Left = 142
Height = 23
Top = 0
Width = 50
BorderSpacing.Left = 8
MaxValue = 10000
TabOrder = 1
OnChange = seToleranceChange
end
object lblTolerance: TLabel
AnchorSideLeft.Control = cbLog
AnchorSideLeft.Side = asrBottom
AnchorSideTop.Control = seTolerance
AnchorSideTop.Side = asrCenter
Left = 83
Height = 15
Top = 4
Width = 51
BorderSpacing.Left = 16
Caption = 'Tolerance'
end
end
object Chart: TChart
Left = 0
Height = 283
Top = 0
Width = 480
AxisList = <
item
Intervals.Count = 10
Intervals.Options = [aipGraphCoords, aipUseCount, aipUseMinLength, aipUseNiceSteps]
Intervals.Tolerance = 5
Marks.LabelBrush.Style = bsClear
Marks.Stripes = csStripes
Minors = <
item
Grid.Visible = False
Intervals.Count = 9
Intervals.MinLength = 5
Intervals.Options = [aipUseCount, aipUseMaxLength, aipUseMinLength, aipUseNiceSteps]
Marks.LabelBrush.Style = bsClear
end>
Title.LabelFont.Orientation = 900
Title.Visible = True
Title.Caption = 'Left'
Title.LabelBrush.Style = bsClear
Transformations = catLog
end
item
Grid.Visible = False
Alignment = calBottom
Marks.LabelBrush.Style = bsClear
Minors = <>
Title.Distance = 0
Title.Visible = True
Title.Caption = 'Bottom'
Title.LabelBrush.Style = bsClear
end
item
Grid.Visible = False
Alignment = calRight
Marks.LabelBrush.Style = bsClear
Minors = <>
Title.LabelFont.Orientation = 900
Title.Visible = True
Title.Caption = 'Right'
Title.LabelBrush.Style = bsClear
end
item
Grid.Visible = False
Alignment = calTop
Arrow.Inverted = True
Inverted = True
Marks.LabelBrush.Style = bsClear
Minors = <>
Title.Caption = 'Top'
Title.LabelBrush.Style = bsClear
end>
Foot.Brush.Color = clBtnFace
Foot.Font.Color = clBlue
Title.Brush.Color = clBtnFace
Title.Font.Color = clBlue
Title.Text.Strings = (
'TAChart'
)
Align = alClient
Color = clWindow
object clsLogPoints: TLineSeries
AxisIndexY = 0
LineType = ltNone
Pointer.Brush.Color = clMaroon
Pointer.Visible = True
ShowPoints = True
end
object cfsLog: TFuncSeries
Extent.UseXMax = True
Extent.UseXMin = True
Extent.XMax = 3
Extent.XMin = -1
AxisIndexY = 0
OnCalculate = cfsLogCalculate
end
end
object csStripes: TChartStyles
Styles = <
item
Brush.Color = 16631498
UsePen = False
end
item
Brush.Color = 12319483
UsePen = False
end>
Left = 104
Top = 56
end
object catLog: TChartAxisTransformations
Left = 104
Top = 112
object ChartAxisTransformations1LinearAxisTransform2: TLinearAxisTransform
Scale = 2
end
object ChartAxisTransformations1LogarithmAxisTransform1: TLogarithmAxisTransform
Base = 10
end
end
end

View File

@ -0,0 +1,76 @@
unit frmLogarithm;
{$mode ObjFPC}{$H+}
interface
uses
SysUtils, Classes, Math,
Forms, Controls, StdCtrls, ExtCtrls, Spin,
TAGraph, TAStyles, TASeries, TAFuncSeries, TATransformations;
type
TLogarithmFrame = class(TFrame)
catLog: TChartAxisTransformations;
cbLog: TCheckBox;
cfsLog: TFuncSeries;
ChartAxisTransformations1LinearAxisTransform2: TLinearAxisTransform;
ChartAxisTransformations1LogarithmAxisTransform1: TLogarithmAxisTransform;
Chart: TChart;
clsLogPoints: TLineSeries;
csStripes: TChartStyles;
lblTolerance: TLabel;
pnlLogControls: TPanel;
seTolerance: TSpinEdit;
procedure cbLogChange(Sender: TObject);
procedure cfsLogCalculate(const AX: Double; out AY: Double);
procedure seToleranceChange(Sender: TObject);
private
public
constructor Create(AOwner: TComponent); override;
end;
implementation
{$R *.lfm}
function MyFunc(AX: Double): Double;
begin
Result := Power(10, AX) + 3;
end;
constructor TLogarithmFrame.Create(AOwner: TComponent);
var
i: Integer;
x: Double;
begin
inherited Create(AOwner);
for i := 0 to 50 do begin
with cfsLog.Extent do
x := i / 50 * (XMax - XMin) + XMin;
clsLogPoints.AddXY(x + Random - 0.5, MyFunc(x) + Random - 0.5);
end;
seTolerance.Value := Chart.LeftAxis.Intervals.Tolerance;
end;
procedure TLogarithmFrame.cbLogChange(Sender: TObject);
begin
ChartAxisTransformations1LogarithmAxisTransform1.Enabled := cbLog.Checked;
end;
procedure TLogarithmFrame.cfsLogCalculate(const AX: Double; out AY: Double);
begin
AY := MyFunc(AX);
end;
procedure TLogarithmFrame.seToleranceChange(Sender: TObject);
begin
Chart.LeftAxis.Intervals.Tolerance := seTolerance.Value;
end;
end.

View File

@ -0,0 +1,181 @@
object NormDistrFrame: TNormDistrFrame
Left = 0
Height = 390
Top = 0
Width = 477
ClientHeight = 390
ClientWidth = 477
TabOrder = 0
DesignLeft = 508
DesignTop = 199
object pnCumulNormDistr: TPanel
Left = 0
Height = 82
Top = 0
Width = 477
Align = alTop
AutoSize = True
BevelOuter = bvNone
ClientHeight = 82
ClientWidth = 477
TabOrder = 0
object rgRandDistr: TRadioGroup
AnchorSideLeft.Control = pnCumulNormDistr
AnchorSideTop.Control = pnCumulNormDistr
Left = 8
Height = 66
Top = 8
Width = 175
AutoFill = True
AutoSize = True
BorderSpacing.Left = 8
BorderSpacing.Top = 8
BorderSpacing.Bottom = 8
Caption = ' Random number generation '
ChildSizing.LeftRightSpacing = 12
ChildSizing.TopBottomSpacing = 4
ChildSizing.EnlargeHorizontal = crsHomogenousChildResize
ChildSizing.EnlargeVertical = crsHomogenousChildResize
ChildSizing.ShrinkHorizontal = crsScaleChilds
ChildSizing.ShrinkVertical = crsScaleChilds
ChildSizing.Layout = cclLeftToRightThenTopToBottom
ChildSizing.ControlsPerLine = 1
ClientHeight = 46
ClientWidth = 171
ItemIndex = 1
Items.Strings = (
'uniform distribution'
'normal distribution'
)
ParentFont = False
TabOrder = 0
OnClick = rgRandDistrClick
end
object cbPercent: TCheckBox
AnchorSideLeft.Control = lblDataCount
AnchorSideTop.Control = edDataCount
AnchorSideTop.Side = asrBottom
Left = 199
Height = 19
Top = 39
Width = 58
BorderSpacing.Top = 8
Caption = 'Percent'
TabOrder = 1
OnChange = cbPercentChange
end
object cbUseAxisTransform: TCheckBox
AnchorSideLeft.Control = edDataCount
AnchorSideTop.Control = cbPercent
Left = 268
Height = 19
Top = 39
Width = 116
BorderSpacing.Bottom = 4
Caption = 'Use AxisTransform'
TabOrder = 2
OnChange = cbUseAxisTransformChange
end
object edDataCount: TSpinEdit
AnchorSideLeft.Control = lblDataCount
AnchorSideLeft.Side = asrBottom
AnchorSideTop.Control = pnCumulNormDistr
Left = 268
Height = 23
Top = 8
Width = 68
Alignment = taRightJustify
BorderSpacing.Left = 8
BorderSpacing.Top = 8
Increment = 50
MaxValue = 1000000
TabOrder = 3
Value = 300
OnChange = edDataCountChange
end
object lblDataCount: TLabel
AnchorSideLeft.Control = rgRandDistr
AnchorSideLeft.Side = asrBottom
AnchorSideTop.Control = edDataCount
AnchorSideTop.Side = asrCenter
Left = 199
Height = 15
Top = 12
Width = 61
BorderSpacing.Left = 16
Caption = 'Data count:'
end
end
object Chart: TChart
Left = 0
Height = 308
Top = 82
Width = 477
AxisList = <
item
Grid.Color = clSilver
Grid.Visible = False
Intervals.Count = 30
Intervals.Options = [aipUseCount, aipUseNiceSteps]
Intervals.Tolerance = 1
Marks.LabelBrush.Style = bsClear
Marks.OverlapPolicy = opHideNeighbour
Minors = <>
Title.LabelFont.Orientation = 900
Title.LabelFont.Style = [fsBold]
Title.Visible = True
Title.Caption = 'Cumulative probability'
Title.LabelBrush.Style = bsClear
Transformations = catCumulNormDistr
end
item
Grid.Color = clSilver
Grid.Visible = False
Alignment = calBottom
Marks.LabelBrush.Style = bsClear
Minors = <>
Title.LabelFont.Style = [fsBold]
Title.Visible = True
Title.Caption = 'Random number'
Title.LabelBrush.Style = bsClear
end>
Extent.XMax = 3
Extent.XMin = -3
Extent.YMax = 3
Extent.YMin = -3
Foot.Brush.Color = clBtnFace
Foot.Font.Color = clBlue
MarginsExternal.Left = 8
MarginsExternal.Right = 12
MarginsExternal.Bottom = 8
Title.Brush.Color = clBtnFace
Title.Font.Color = clBlue
Title.Text.Strings = (
'TAChart'
)
Align = alClient
Color = clWindow
object ChartLineSeries1: TLineSeries
AxisIndexX = 1
AxisIndexY = 0
Pointer.Brush.Color = clBlue
Pointer.HorizSize = 2
Pointer.Pen.Color = clBlue
Pointer.Style = psCircle
Pointer.VertSize = 2
Pointer.Visible = True
ShowPoints = True
end
end
object catCumulNormDistr: TChartAxisTransformations
Left = 112
Top = 192
object catCumulNormDistrLinearAxisTransform1: TLinearAxisTransform
Enabled = False
Scale = 0.01
end
object catCumulNormDistrCumulNormDistrAxisTransform1: TCumulNormDistrAxisTransform
Enabled = False
end
end
end

View File

@ -0,0 +1,101 @@
unit frmNormDistr;
{$mode ObjFPC}{$H+}
interface
uses
SysUtils, Classes, StrUtils, Math,
Forms, Controls, StdCtrls, ExtCtrls, Spin,
TAGraph, TASources, TASeries, TATransformations;
type
TNormDistrFrame = class(TFrame)
catCumulNormDistr: TChartAxisTransformations;
catCumulNormDistrCumulNormDistrAxisTransform1: TCumulNormDistrAxisTransform;
catCumulNormDistrLinearAxisTransform1: TLinearAxisTransform;
cbPercent: TCheckBox;
cbUseAxisTransform: TCheckBox;
Chart: TChart;
ChartLineSeries1: TLineSeries;
edDataCount: TSpinEdit;
lblDataCount: TLabel;
pnCumulNormDistr: TPanel;
rgRandDistr: TRadioGroup;
procedure cbPercentChange(Sender: TObject);
procedure cbUseAxisTransformChange(Sender: TObject);
procedure edDataCountChange(Sender: TObject);
procedure rgRandDistrClick(Sender: TObject);
private
procedure FillCumulNormDistrSource;
public
constructor Create(AOwner: TComponent); override;
end;
implementation
{$R *.lfm}
constructor TNormDistrFrame.Create(AOwner: TComponent);
begin
inherited;
FillCumulNormDistrSource;
end;
procedure TNormDistrFrame.cbPercentChange(Sender: TObject);
begin
catCumulNormDistrLinearAxisTransform1.Enabled := cbPercent.Checked;
FillCumulNormDistrSource;
Chart.LeftAxis.Title.Caption :=
'Cumulative probability' + IfThen(cbPercent.Checked, ' (%)', '');
end;
procedure TNormDistrFrame.cbUseAxisTransformChange(Sender: TObject);
begin
catCumulNormDistrCumulNormDistrAxisTransform1.Enabled := cbUseAxisTransform.Checked;
end;
procedure TNormDistrFrame.edDataCountChange(Sender: TObject);
begin
FillCumulNormDistrSource;
end;
procedure TNormDistrFrame.FillCumulNormDistrSource;
var
i: Integer;
y: Double;
s: TListChartSource;
begin
RandSeed := 976896;
s := ChartLineSeries1.ListSource;
s.BeginUpdate;
try
s.Clear;
// Add random test data as x values --> random values will
// get sorted in ascending direction automatically.
s.Sorted := false;
for i := 1 to edDataCount.Value do
case rgRandDistr.ItemIndex of
0: s.Add(Random, 0);
1: s.Add(RandG(0.0, 1.0), 0);
end;
s.Sorted := true;
// Calculate cumulative probability from index in sorted list.
for i := 0 to s.Count - 1 do begin
y := (i + 1) / (s.Count + 1); // Add 1 since y=0 and y=1 are not valid.
s.Item[i]^.Y := IfThen(CbPercent.Checked, y * 100, y);
end;
finally
s.EndUpdate;
end;
end;
procedure TNormDistrFrame.rgRandDistrClick(Sender: TObject);
begin
FillCumulNormDistrSource;
end;
end.

View File

@ -0,0 +1,80 @@
object UserFrame: TUserFrame
Left = 0
Height = 332
Top = 0
Width = 503
ClientHeight = 332
ClientWidth = 503
TabOrder = 0
DesignLeft = 314
DesignTop = 130
object Chart: TChart
Left = 0
Height = 332
Top = 0
Width = 503
AxisList = <
item
Marks.LabelBrush.Style = bsClear
Minors = <>
Title.LabelFont.Orientation = 900
Title.LabelBrush.Style = bsClear
end
item
Grid.Visible = False
Intervals.Count = 20
Intervals.MinLength = 20
Intervals.NiceSteps = '0.2|0.25|0.4|0.5|1.0'
Intervals.Options = [aipGraphCoords, aipUseCount, aipUseMaxLength, aipUseMinLength, aipUseNiceSteps]
Alignment = calBottom
Marks.LabelBrush.Style = bsClear
Minors = <>
Title.LabelBrush.Style = bsClear
Transformations = catUser
end>
Foot.Brush.Color = clBtnFace
Foot.Font.Color = clBlue
Title.Text.Strings = (
'Drag purple line to locally zoom in various axis segments'
)
Title.Visible = True
Toolset = ChartToolset1
Align = alClient
Color = clWindow
object LineSeries: TLineSeries
AxisIndexX = 1
Source = rcsUser
end
object VerticalLine: TConstantLine
AxisIndex = 1
LineStyle = lsVertical
Pen.Color = clFuchsia
Pen.Width = 2
Position = 20
end
end
object rcsUser: TRandomChartSource
PointsNumber = 100
RandSeed = 1999979507
XMax = 50
YMax = 20
YMin = 10
Left = 115
Top = 236
end
object ChartToolset1: TChartToolset
Left = 115
Top = 72
object DataPointDragTool: TDataPointDragTool
Shift = [ssLeft]
AffectedSeries = '1'
end
end
object catUser: TChartAxisTransformations
Left = 272
Top = 236
object catUserUserDefinedAxisTransform1: TUserDefinedAxisTransform
OnAxisToGraph = catUserUserDefinedAxisTransform1AxisToGraph
end
end
end

View File

@ -0,0 +1,50 @@
unit frmUser;
{$mode ObjFPC}{$H+}
interface
uses
Classes, SysUtils, Forms, Controls,
TAGraph, TASeries, TASources, TATools, TATransformations;
type
TUserFrame = class(TFrame)
catUser: TChartAxisTransformations;
catUserUserDefinedAxisTransform1: TUserDefinedAxisTransform;
ChartToolset1: TChartToolset;
DataPointDragTool: TDataPointDragTool;
Chart: TChart;
VerticalLine: TConstantLine;
LineSeries: TLineSeries;
rcsUser: TRandomChartSource;
procedure catUserUserDefinedAxisTransform1AxisToGraph(AX: Double; out AT:
Double);
private
public
end;
implementation
{$R *.lfm}
procedure TUserFrame.catUserUserDefinedAxisTransform1AxisToGraph(AX: Double;
out AT: Double);
const
R1 = 8.0;
C = 2.5;
R2 = R1 / C;
var
zx: Double;
begin
zx := VerticalLine.Position;
if Abs(AX - zx) > R1 then AT := AX
else if AX < zx - R2 then AT := zx - R1
else if AX > zx + R2 then AT := zx + R1
else AT := (AX - zx + R2) * C + zx - R1;
end;
end.

View File

@ -1,15 +1,15 @@
object Form1: TForm1
object MainForm: TMainForm
Left = 559
Height = 434
Top = 158
Width = 533
Caption = 'TAChart axis transformation demo'
Caption = 'TAChart Axis Transformation Demo'
ClientHeight = 434
ClientWidth = 533
OnCreate = FormCreate
Position = poScreenCenter
LCLVersion = '2.3.0.0'
object PageControl1: TPageControl
LCLVersion = '4.99.0.0'
OnCreate = FormCreate
object PageControl: TPageControl
Left = 0
Height = 434
Top = 0
@ -20,747 +20,18 @@ object Form1: TForm1
TabOrder = 0
object tsLinear: TTabSheet
Caption = 'Linear'
ClientHeight = 406
ClientWidth = 525
object ChartT: TChart
Left = 0
Height = 371
Top = 0
Width = 525
AxisList = <
item
Grid.Visible = False
TickColor = clRed
AxisPen.Color = clRed
AxisPen.Visible = True
Marks.LabelFont.Color = clRed
Marks.AtDataOnly = True
Marks.LabelBrush.Style = bsClear
Minors = <>
Title.LabelFont.Color = clRed
Title.LabelFont.Orientation = 900
Title.Visible = True
Title.Caption = 'Summer temperature, °C'
Title.LabelBrush.Style = bsClear
Transformations = catTAuto
end
item
Intervals.MaxLength = 100
Intervals.MinLength = 20
Alignment = calBottom
Marks.LabelBrush.Style = bsClear
Minors = <>
Title.Visible = True
Title.Caption = 'Year'
Title.LabelBrush.Style = bsClear
end
item
Grid.Visible = False
TickColor = clBlue
Alignment = calRight
AxisPen.Color = clBlue
AxisPen.Visible = True
Marks.Distance = 4
Marks.LabelFont.Color = clBlue
Marks.AtDataOnly = True
Marks.LabelBrush.Style = bsClear
Minors = <>
Title.LabelFont.Color = clBlue
Title.LabelFont.Orientation = 900
Title.Visible = True
Title.Caption = 'Winter temperature, °F'
Title.LabelBrush.Style = bsClear
Transformations = catT
end>
Foot.Brush.Color = clBtnFace
Foot.Font.Color = clBlue
Frame.Visible = False
Title.Brush.Color = clBtnFace
Title.Font.Color = clBlue
Title.Text.Strings = (
'TAChart'
)
Align = alClient
Color = clWindow
object ChartTSummer: TLineSeries
AxisIndexY = 0
LinePen.Color = clRed
LinePen.Width = 2
Source = rcsTSummer
end
object ChartTWinterLine: TLineSeries
AxisIndexY = 2
LinePen.Color = clBlue
LinePen.Width = 2
Source = rcsTWinter
end
object ChartTWinterBar: TBarSeries
AxisIndexY = 2
BarBrush.Color = clBlue
BarBrush.Style = bsDiagCross
Source = rcsTWinter
end
end
object pnlAutoControls: TPanel
Left = 0
Height = 35
Top = 371
Width = 525
Align = alBottom
AutoSize = True
BevelOuter = bvNone
ClientHeight = 35
ClientWidth = 525
TabOrder = 1
object cbAuto: TCheckBox
AnchorSideLeft.Control = pnlAutoControls
AnchorSideTop.Control = pnlAutoControls
AnchorSideTop.Side = asrCenter
Left = 8
Height = 19
Top = 8
Width = 73
BorderSpacing.Left = 8
BorderSpacing.Top = 8
BorderSpacing.Bottom = 8
Caption = 'Auto scale'
OnChange = cbAutoChange
TabOrder = 0
end
end
end
object tsIndependent: TTabSheet
Caption = 'Independent scale'
ClientHeight = 406
ClientWidth = 525
object ChartIndependent: TChart
Left = 0
Height = 347
Top = 0
Width = 525
AxisList = <
item
Grid.Visible = False
Intervals.Tolerance = 1
TickColor = clNavy
Marks.LabelFont.Color = clNavy
Marks.LabelFont.Style = [fsBold]
Marks.LabelBrush.Style = bsClear
Minors = <>
Title.LabelFont.Orientation = 900
Title.LabelBrush.Style = bsClear
Transformations = catIndependent1
end
item
Grid.Visible = False
Alignment = calBottom
Marks.Visible = False
Marks.LabelBrush.Style = bsClear
Minors = <>
Title.LabelBrush.Style = bsClear
end
item
Grid.Visible = False
Intervals.Tolerance = 1
TickColor = clGreen
Alignment = calRight
Marks.LabelFont.Color = clGreen
Marks.LabelFont.Style = [fsBold]
Marks.LabelBrush.Style = bsClear
Minors = <>
Title.LabelBrush.Style = bsClear
Transformations = catIndependent2
end>
Foot.Brush.Color = clBtnFace
Foot.Font.Color = clBlue
Title.Brush.Color = clBtnFace
Title.Font.Color = clBlue
Title.Text.Strings = (
'TAChart'
)
Align = alClient
Color = clWhite
object ChartIndependentLineSeries1: TLineSeries
AxisIndexY = 0
LinePen.Color = clNavy
LinePen.Width = 2
end
object ChartIndependentLineSeries2: TLineSeries
AxisIndexY = 2
LinePen.Color = clGreen
LinePen.Width = 2
end
end
object pnlIndependentControls: TPanel
Left = 4
Height = 51
Top = 351
Width = 517
Align = alBottom
AutoSize = True
BorderSpacing.Around = 4
BevelOuter = bvNone
ClientHeight = 51
ClientWidth = 517
TabOrder = 1
object fseIndependent1: TFloatSpinEdit
AnchorSideLeft.Control = lblIndependentScale1
AnchorSideLeft.Side = asrBottom
AnchorSideTop.Control = rgSyncAxisMarks
AnchorSideTop.Side = asrCenter
Left = 63
Height = 23
Top = 14
Width = 70
BorderSpacing.Left = 8
Increment = 0.1
MaxValue = 10
MinValue = 0.1
OnChange = fseIndependent1Change
TabOrder = 0
Value = 1
end
object fseIndependent2: TFloatSpinEdit
AnchorSideLeft.Control = lblIndependentScale2
AnchorSideLeft.Side = asrBottom
AnchorSideTop.Control = rgSyncAxisMarks
AnchorSideTop.Side = asrCenter
Left = 196
Height = 23
Top = 14
Width = 70
BorderSpacing.Left = 8
Increment = 0.1
MaxValue = 10
MinValue = 0.1
OnChange = fseIndependent2Change
TabOrder = 1
Value = 1
end
object lblIndependentScale1: TLabel
AnchorSideLeft.Control = pnlIndependentControls
AnchorSideTop.Control = fseIndependent1
AnchorSideTop.Side = asrCenter
Left = 16
Height = 15
Top = 18
Width = 39
BorderSpacing.Left = 16
Caption = 'Scale 1'
Font.Color = clNavy
Font.Style = [fsBold]
ParentFont = False
end
object lblIndependentScale2: TLabel
AnchorSideLeft.Control = fseIndependent1
AnchorSideLeft.Side = asrBottom
AnchorSideTop.Control = fseIndependent2
AnchorSideTop.Side = asrCenter
Left = 149
Height = 15
Top = 18
Width = 39
BorderSpacing.Left = 16
Caption = 'Scale 2'
Font.Color = clGreen
Font.Style = [fsBold]
ParentFont = False
end
object rgSyncAxisMarks: TRadioGroup
AnchorSideRight.Side = asrBottom
Left = 330
Height = 51
Top = 0
Width = 187
Align = alRight
AutoFill = True
AutoSize = True
BorderSpacing.InnerBorder = 4
Caption = ' Synchronize marks '
ChildSizing.LeftRightSpacing = 12
ChildSizing.TopBottomSpacing = 2
ChildSizing.HorizontalSpacing = 10
ChildSizing.EnlargeHorizontal = crsHomogenousChildResize
ChildSizing.EnlargeVertical = crsHomogenousChildResize
ChildSizing.ShrinkHorizontal = crsScaleChilds
ChildSizing.ShrinkVertical = crsScaleChilds
ChildSizing.Layout = cclLeftToRightThenTopToBottom
ChildSizing.ControlsPerLine = 3
ClientHeight = 31
ClientWidth = 183
Columns = 3
ItemIndex = 1
Items.Strings = (
'Left'
'None'
'Right'
)
OnClick = rgSyncAxisMarksClick
TabOrder = 2
end
end
end
object tsLog: TTabSheet
Caption = 'Logarithm'
ClientHeight = 406
ClientWidth = 525
object ChartLog: TChart
Left = 0
Height = 367
Top = 0
Width = 525
AxisList = <
item
Intervals.Count = 10
Intervals.Options = [aipGraphCoords, aipUseCount, aipUseMinLength, aipUseNiceSteps]
Intervals.Tolerance = 5
Marks.LabelBrush.Style = bsClear
Marks.Stripes = csStripes
Minors = <
item
Grid.Visible = False
Intervals.Count = 9
Intervals.MinLength = 5
Intervals.Options = [aipUseCount, aipUseMaxLength, aipUseMinLength, aipUseNiceSteps]
Marks.LabelBrush.Style = bsClear
end>
Title.LabelFont.Orientation = 900
Title.Visible = True
Title.Caption = 'Left'
Title.LabelBrush.Style = bsClear
Transformations = catLog
end
item
Grid.Visible = False
Alignment = calBottom
Marks.LabelBrush.Style = bsClear
Minors = <>
Title.Distance = 0
Title.Visible = True
Title.Caption = 'Bottom'
Title.LabelBrush.Style = bsClear
end
item
Grid.Visible = False
Alignment = calRight
Marks.LabelBrush.Style = bsClear
Minors = <>
Title.LabelFont.Orientation = 900
Title.Visible = True
Title.Caption = 'Right 1'
Title.LabelBrush.Style = bsClear
end
item
Grid.Visible = False
Alignment = calTop
Arrow.Inverted = True
Inverted = True
Marks.LabelBrush.Style = bsClear
Minors = <>
Title.Caption = 'Top'
Title.LabelBrush.Style = bsClear
end>
Foot.Brush.Color = clBtnFace
Foot.Font.Color = clBlue
Title.Brush.Color = clBtnFace
Title.Font.Color = clBlue
Title.Text.Strings = (
'TAChart'
)
Align = alClient
Color = clWindow
object clsLogPoints: TLineSeries
AxisIndexY = 0
LineType = ltNone
Pointer.Brush.Color = clMaroon
Pointer.Visible = True
ShowPoints = True
end
object cfsLog: TFuncSeries
Extent.UseXMax = True
Extent.UseXMin = True
Extent.XMax = 3
Extent.XMin = -1
AxisIndexY = 0
OnCalculate = ChartLogFuncSeries1Calculate
end
end
object pnlLogControls: TPanel
Left = 8
Height = 23
Top = 375
Width = 509
Align = alBottom
AutoSize = True
BorderSpacing.Around = 8
BevelOuter = bvNone
ClientHeight = 23
ClientWidth = 509
TabOrder = 1
object cbLog: TCheckBox
AnchorSideLeft.Control = pnlLogControls
AnchorSideTop.Control = seTolerance
AnchorSideTop.Side = asrCenter
Left = 0
Height = 19
Top = 2
Width = 67
Caption = 'Log scale'
Checked = True
OnChange = cbLogChange
State = cbChecked
TabOrder = 0
end
object seTolerance: TSpinEdit
AnchorSideLeft.Control = lblTolerance
AnchorSideLeft.Side = asrBottom
AnchorSideTop.Control = pnlLogControls
Left = 141
Height = 23
Top = 0
Width = 50
BorderSpacing.Left = 8
MaxValue = 10000
OnChange = seToleranceChange
TabOrder = 1
end
object lblTolerance: TLabel
AnchorSideLeft.Control = cbLog
AnchorSideLeft.Side = asrBottom
AnchorSideTop.Control = seTolerance
AnchorSideTop.Side = asrCenter
Left = 83
Height = 15
Top = 4
Width = 50
BorderSpacing.Left = 16
Caption = 'Tolerance'
end
end
end
object tsCumulNormDistr: TTabSheet
Caption = 'Normal distribution'
ClientHeight = 406
ClientWidth = 525
object ChartCumulNormDistr: TChart
Left = 0
Height = 324
Top = 82
Width = 525
AxisList = <
item
Grid.Color = clSilver
Grid.Visible = False
Intervals.Count = 30
Intervals.Options = [aipUseCount, aipUseNiceSteps]
Intervals.Tolerance = 1
Marks.LabelBrush.Style = bsClear
Marks.OverlapPolicy = opHideNeighbour
Minors = <>
Title.LabelFont.Orientation = 900
Title.LabelFont.Style = [fsBold]
Title.Visible = True
Title.Caption = 'Cumulative probability'
Title.LabelBrush.Style = bsClear
Transformations = catCumulNormDistr
end
item
Grid.Color = clSilver
Grid.Visible = False
Alignment = calBottom
Marks.LabelBrush.Style = bsClear
Minors = <>
Title.LabelFont.Style = [fsBold]
Title.Visible = True
Title.Caption = 'Random number'
Title.LabelBrush.Style = bsClear
end>
Extent.XMax = 3
Extent.XMin = -3
Extent.YMax = 3
Extent.YMin = -3
Foot.Brush.Color = clBtnFace
Foot.Font.Color = clBlue
MarginsExternal.Left = 8
MarginsExternal.Right = 12
MarginsExternal.Bottom = 8
Title.Brush.Color = clBtnFace
Title.Font.Color = clBlue
Title.Text.Strings = (
'TAChart'
)
Align = alClient
Color = clWindow
object ChartCumulNormDistrLineSeries1: TLineSeries
AxisIndexX = 1
AxisIndexY = 0
Pointer.Brush.Color = clBlue
Pointer.HorizSize = 2
Pointer.Pen.Color = clBlue
Pointer.Style = psCircle
Pointer.VertSize = 2
Pointer.Visible = True
ShowPoints = True
end
end
object pnCumulNormDistr: TPanel
Left = 0
Height = 82
Top = 0
Width = 525
Align = alTop
AutoSize = True
BevelOuter = bvNone
ClientHeight = 82
ClientWidth = 525
TabOrder = 1
object rgRandDistr: TRadioGroup
AnchorSideLeft.Control = pnCumulNormDistr
AnchorSideTop.Control = pnCumulNormDistr
Left = 8
Height = 66
Top = 8
Width = 175
AutoFill = True
AutoSize = True
BorderSpacing.Left = 8
BorderSpacing.Top = 8
BorderSpacing.Bottom = 8
Caption = ' Random number generation '
ChildSizing.LeftRightSpacing = 12
ChildSizing.TopBottomSpacing = 4
ChildSizing.EnlargeHorizontal = crsHomogenousChildResize
ChildSizing.EnlargeVertical = crsHomogenousChildResize
ChildSizing.ShrinkHorizontal = crsScaleChilds
ChildSizing.ShrinkVertical = crsScaleChilds
ChildSizing.Layout = cclLeftToRightThenTopToBottom
ChildSizing.ControlsPerLine = 1
ClientHeight = 46
ClientWidth = 171
ItemIndex = 1
Items.Strings = (
'uniform distribution'
'normal distribution'
)
OnClick = rgRandDistrClick
ParentFont = False
TabOrder = 0
end
object cbPercent: TCheckBox
AnchorSideLeft.Control = lblDataCount
AnchorSideTop.Control = edDataCount
AnchorSideTop.Side = asrBottom
Left = 199
Height = 19
Top = 39
Width = 58
BorderSpacing.Top = 8
Caption = 'Percent'
OnChange = cbPercentChange
TabOrder = 1
end
object cbUseAxisTransform: TCheckBox
AnchorSideLeft.Control = edDataCount
AnchorSideTop.Control = cbPercent
Left = 268
Height = 19
Top = 39
Width = 116
BorderSpacing.Bottom = 4
Caption = 'Use AxisTransform'
OnChange = cbUseAxisTransformChange
TabOrder = 2
end
object edDataCount: TSpinEdit
AnchorSideLeft.Control = lblDataCount
AnchorSideLeft.Side = asrBottom
AnchorSideTop.Control = pnCumulNormDistr
Left = 268
Height = 23
Top = 8
Width = 82
BorderSpacing.Left = 8
BorderSpacing.Top = 8
Increment = 50
MaxValue = 1000000
OnChange = edDataCountChange
TabOrder = 3
Value = 300
end
object lblDataCount: TLabel
AnchorSideLeft.Control = rgRandDistr
AnchorSideLeft.Side = asrBottom
AnchorSideTop.Control = edDataCount
AnchorSideTop.Side = asrCenter
Left = 199
Height = 15
Top = 12
Width = 61
BorderSpacing.Left = 16
Caption = 'Data count:'
end
end
end
object tsUser: TTabSheet
Caption = 'User defined'
ClientHeight = 406
ClientWidth = 525
object ChartUser: TChart
Left = 0
Height = 406
Top = 0
Width = 525
AxisList = <
item
Marks.LabelBrush.Style = bsClear
Minors = <>
Title.LabelFont.Orientation = 900
Title.LabelBrush.Style = bsClear
end
item
Grid.Visible = False
Intervals.Count = 20
Intervals.MinLength = 20
Intervals.NiceSteps = '0.2|0.25|0.4|0.5|1.0'
Intervals.Options = [aipGraphCoords, aipUseCount, aipUseMaxLength, aipUseMinLength, aipUseNiceSteps]
Alignment = calBottom
Marks.LabelBrush.Style = bsClear
Minors = <>
Title.LabelBrush.Style = bsClear
Transformations = catUser
end>
Foot.Brush.Color = clBtnFace
Foot.Font.Color = clBlue
Title.Text.Strings = (
'Drag purple line to locally zoom in various axis segments'
)
Title.Visible = True
Toolset = ChartToolset1
Align = alClient
Color = clWindow
object ChartUserLineSeries1: TLineSeries
AxisIndexX = 1
Source = rcsUser
end
object ChartUserConstantLine1: TConstantLine
AxisIndex = 1
LineStyle = lsVertical
Pen.Color = clFuchsia
Pen.Width = 2
Position = 20
end
end
end
end
object catLog: TChartAxisTransformations
Left = 216
Top = 60
object ChartAxisTransformations1LinearAxisTransform2: TLinearAxisTransform
Scale = 2
end
object ChartAxisTransformations1LogarithmAxisTransform1: TLogarithmAxisTransform
Base = 10
end
end
object catT: TChartAxisTransformations
Left = 352
Top = 60
object catTFahrToCel: TLinearAxisTransform
Offset = -17.777777777
Scale = 0.5555555555
end
object catTAutoScaleAxisTransform1: TAutoScaleAxisTransform
Enabled = False
end
end
object rcsTSummer: TRandomChartSource
PointsNumber = 20
RandSeed = 114536250
XMax = 2009
XMin = 1990
YMax = 25
Left = 87
Top = 106
end
object rcsTWinter: TRandomChartSource
PointsNumber = 20
RandSeed = 23453245
XMax = 2009
XMin = 1990
YMax = 20
YMin = -15
Left = 87
Top = 156
end
object catTAuto: TChartAxisTransformations
Left = 352
Top = 112
object catTAutoAutoScaleAxisTransform1: TAutoScaleAxisTransform
Enabled = False
end
end
object csStripes: TChartStyles
Styles = <
item
Brush.Color = 16631498
UsePen = False
end
item
Brush.Color = 12319483
UsePen = False
end>
Left = 352
Top = 176
end
object rcsUser: TRandomChartSource
PointsNumber = 100
RandSeed = 1999979507
XMax = 50
YMax = 20
YMin = 10
Left = 87
Top = 208
end
object catUser: TChartAxisTransformations
Left = 352
Top = 236
object catUserUserDefinedAxisTransform1: TUserDefinedAxisTransform
OnAxisToGraph = catUserUserDefinedAxisTransform1AxisToGraph
end
end
object ChartToolset1: TChartToolset
Left = 216
Top = 116
object ChartToolset1DataPointDragTool1: TDataPointDragTool
Shift = [ssLeft]
AffectedSeries = '1'
end
end
object catIndependent1: TChartAxisTransformations
Left = 220
Top = 176
object catIndependent1Zoom: TLinearAxisTransform
end
end
object catIndependent2: TChartAxisTransformations
Left = 220
Top = 236
object catIndependent2Zoom: TLinearAxisTransform
end
end
object AxLabelSource: TListChartSource
Left = 311
Top = 305
end
object catCumulNormDistr: TChartAxisTransformations
Left = 310
Top = 305
object catCumulNormDistrLinearAxisTransform1: TLinearAxisTransform
Enabled = False
Scale = 0.01
end
object catCumulNormDistrCumulNormDistrAxisTransform1: TCumulNormDistrAxisTransform
Enabled = False
end
end
end

View File

@ -5,270 +5,62 @@ unit Main;
interface
uses
ComCtrls, ExtCtrls, Forms, Spin, StdCtrls, Classes,
TAAxisSource, TAFuncSeries, TAGraph, TASeries, TASources, TAStyles, TATools,
TATransformations;
Classes, Forms, Controls, ComCtrls,
frmLinear, frmIndependent, frmLogarithm, frmNormDistr, frmUser;
type
{ TForm1 }
{ TMainForm }
TForm1 = class(TForm)
AxLabelSource: TListChartSource;
catCumulNormDistrCumulNormDistrAxisTransform1: TCumulNormDistrAxisTransform;
catCumulNormDistrLinearAxisTransform1: TLinearAxisTransform;
catIndependent1Zoom: TLinearAxisTransform;
catIndependent2Zoom: TLinearAxisTransform;
catIndependent2: TChartAxisTransformations;
catTAutoAutoScaleAxisTransform1: TAutoScaleAxisTransform;
catTAutoScaleAxisTransform1: TAutoScaleAxisTransform;
catTAuto: TChartAxisTransformations;
cbAuto: TCheckBox;
catUser: TChartAxisTransformations;
catUserUserDefinedAxisTransform1: TUserDefinedAxisTransform;
catIndependent1: TChartAxisTransformations;
cbPercent: TCheckBox;
cbUseAxisTransform: TCheckBox;
ChartCumulNormDistr: TChart;
catCumulNormDistr: TChartAxisTransformations;
ChartIndependent: TChart;
ChartIndependentLineSeries1: TLineSeries;
ChartIndependentLineSeries2: TLineSeries;
ChartCumulNormDistrLineSeries1: TLineSeries;
ChartToolset1: TChartToolset;
ChartToolset1DataPointDragTool1: TDataPointDragTool;
ChartUser: TChart;
ChartUserConstantLine1: TConstantLine;
ChartUserLineSeries1: TLineSeries;
csStripes: TChartStyles;
ChartLog: TChart;
cfsLog: TFuncSeries;
cbLog: TCheckBox;
ChartTWinterBar: TBarSeries;
clsLogPoints: TLineSeries;
ChartT: TChart;
catLog: TChartAxisTransformations;
ChartAxisTransformations1LinearAxisTransform2: TLinearAxisTransform;
ChartAxisTransformations1LogarithmAxisTransform1: TLogarithmAxisTransform;
catT: TChartAxisTransformations;
catTFahrToCel: TLinearAxisTransform;
ChartTSummer: TLineSeries;
ChartTWinterLine: TLineSeries;
edDataCount: TSpinEdit;
fseIndependent1: TFloatSpinEdit;
fseIndependent2: TFloatSpinEdit;
lblTolerance: TLabel;
lblDataCount: TLabel;
lblIndependentScale1: TLabel;
lblIndependentScale2: TLabel;
PageControl1: TPageControl;
pnCumulNormDistr: TPanel;
pnlIndependentControls: TPanel;
pnlLogControls: TPanel;
pnlAutoControls: TPanel;
rgSyncAxisMarks: TRadioGroup;
rcsUser: TRandomChartSource;
rcsTSummer: TRandomChartSource;
rcsTWinter: TRandomChartSource;
rgRandDistr: TRadioGroup;
seTolerance: TSpinEdit;
TMainForm = class(TForm)
PageControl: TPageControl;
tsLinear: TTabSheet;
tsCumulNormDistr: TTabSheet;
tsIndependent: TTabSheet;
tsUser: TTabSheet;
tsLog: TTabSheet;
procedure cbAutoChange(Sender: TObject);
procedure cbLogChange(Sender: TObject);
procedure catUserUserDefinedAxisTransform1AxisToGraph(
AX: Double; out AT: Double);
procedure cbPercentChange(Sender: TObject);
procedure cbUseAxisTransformChange(Sender: TObject);
procedure ChartLogFuncSeries1Calculate(const AX: Double; out AY: Double);
procedure edDataCountChange(Sender: TObject);
procedure FormCreate(Sender: TObject);
procedure fseIndependent1Change(Sender: TObject);
procedure fseIndependent2Change(Sender: TObject);
procedure rgRandDistrClick(Sender: TObject);
procedure rgSyncAxisMarksClick(Sender: TObject);
procedure seToleranceChange(Sender: TObject);
private
FAxisSource: TCustomAxisChartSource;
procedure FillIndependentSource;
procedure FillCumulNormDistrSource;
FLinearFrame: TLinearFrame;
FIndependentScaleFrame: TIndependentScaleFrame;
FLogarithmFrame: TLogarithmFrame;
FNormDistrFrame: TNormDistrFrame;
FUserFrame: TUserFrame;
end;
var
Form1: TForm1;
MainForm: TMainForm;
implementation
uses
Math, StrUtils, SysUtils, TAChartAxis, TAChartAxisUtils, TAChartUtils;
{$R *.lfm}
function MyFunc(AX: Double): Double;
begin
Result := Power(10, AX) + 3;
end;
{ TMainForm }
{ TForm1 }
procedure TForm1.cbAutoChange(Sender: TObject);
begin
catTAutoAutoScaleAxisTransform1.Enabled := cbAuto.Checked;
catTAutoScaleAxisTransform1.Enabled := cbAuto.Checked;
end;
procedure TForm1.cbLogChange(Sender: TObject);
begin
ChartAxisTransformations1LogarithmAxisTransform1.Enabled := cbLog.Checked;
end;
procedure TForm1.cbPercentChange(Sender: TObject);
begin
catCumulNormDistrLinearAxisTransform1.Enabled := cbPercent.Checked;
FillCumulNormDistrSource;
ChartCumulNormDistr.LeftAxis.Title.Caption :=
'Cumulative probability' + IfThen(cbPercent.Checked, ' (%)', '');
end;
procedure TForm1.cbUseAxisTransformChange(Sender: TObject);
begin
catCumulNormDistrCumulNormDistrAxisTransform1.Enabled :=
cbUseAxisTransform.Checked;
end;
procedure TForm1.catUserUserDefinedAxisTransform1AxisToGraph(
AX: Double; out AT: Double);
const
R1 = 8.0;
C = 2.5;
R2 = R1 / C;
var
zx: Double;
begin
zx := ChartUserConstantLine1.Position;
if Abs(AX - zx) > R1 then AT := AX
else if AX < zx - R2 then AT := zx - R1
else if AX > zx + R2 then AT := zx + R1
else AT := (AX - zx + R2) * C + zx - R1;
end;
procedure TForm1.ChartLogFuncSeries1Calculate(const AX: Double; out AY: Double);
begin
AY := MyFunc(AX);
end;
procedure TForm1.edDataCountChange(Sender: TObject);
begin
FillCumulNormDistrSource;
end;
procedure TForm1.FillCumulNormDistrSource;
var
i: Integer;
y: Double;
s: TListChartSource;
begin
RandSeed := 976896;
s := ChartCumulNormDistrLineSeries1.ListSource;
s.BeginUpdate;
try
s.Clear;
// Add random test data as x values --> random values will
// get sorted in ascending direction automatically.
s.Sorted := false;
for i := 1 to edDataCount.Value do
case rgRandDistr.ItemIndex of
0: s.Add(Random, 0);
1: s.Add(RandG(0.0, 1.0), 0);
end;
s.Sorted := true;
// Calculate cumulative probability from index in sorted list.
for i := 0 to s.Count - 1 do begin
y := (i + 1) / (s.Count + 1); // Add 1 since y=0 and y=1 are not valid.
s.Item[i]^.Y := IfThen(CbPercent.Checked, y * 100, y);
end;
finally
s.EndUpdate;
end;
end;
procedure TForm1.FillIndependentSource;
var
i: Integer;
v1, v2: Double;
begin
RandSeed := 923875;
v1 := 0;
v2 := 0;
for i := 1 to 100 do begin
v1 += Random - 0.48;
v2 += Random - 0.52;
ChartIndependentLineSeries1.AddXY(i, v1);
ChartIndependentLineSeries2.AddXY(i, v2);
end;
end;
procedure TForm1.FormCreate(Sender: TObject);
procedure TMainForm.FormCreate(Sender: TObject);
var
i: Integer;
x: Double;
begin
for i := 0 to 50 do begin
with cfsLog.Extent do
x := i / 50 * (XMax - XMin) + XMin;
clsLogPoints.AddXY(x + Random - 0.5, MyFunc(x) + Random - 0.5);
end;
FillIndependentSource;
FillCumulNormDistrSource;
seTolerance.Value := ChartLog.LeftAxis.Intervals.Tolerance;
FAxisSource := TCustomAxisChartSource.Create(Self);
end;
FLinearFrame := TLinearFrame.Create(Self);
FLinearFrame.Parent := tsLinear;
FLinearFrame.Align := alClient;
procedure TForm1.fseIndependent1Change(Sender: TObject);
begin
catIndependent1Zoom.Scale := fseIndependent1.Value;
end;
FIndependentScaleFrame := TIndependentScaleFrame.Create(Self);
FIndependentScaleFrame.Parent := tsIndependent;
FIndependentScaleFrame.Align := alClient;
procedure TForm1.fseIndependent2Change(Sender: TObject);
begin
catIndependent2Zoom.Scale := fseIndependent2.Value;
end;
FLogarithmFrame := TLogarithmFrame.Create(Self);
FLogarithmFrame.Parent := tsLog;
FLogarithmFrame.Align := alClient;
procedure TForm1.rgRandDistrClick(Sender: TObject);
begin
FillCumulNormDistrSource;
end;
FNormDistrFrame := TNormDistrFrame.Create(Self);
FNormDistrFrame.Parent := tsCumulNormDistr;
FNormDistrFrame.Align := alClient;
procedure TForm1.rgSyncAxisMarksClick(Sender: TObject);
var
la, ra: TChartAxis;
begin
la := ChartIndependent.LeftAxis;
ra := ChartIndependent.AxisList.GetAxisByAlign(calRight);
la.Marks.Source := nil;
ra.Marks.Source := nil;
case rgSyncAxisMarks.ItemIndex of
0: begin
FAxisSource.AxisFrom := ra;
FAxisSource.AxisTo := la;
la.Marks.Source := FAxisSource;
end;
2: begin
FAxisSource.AxisFrom := la;
FAxisSource.AxisTo := ra;
ra.Marks.Source := FAxisSource;
end;
end;
la.Grid.Visible := rgSyncAxisMarks.ItemIndex <> 1;
end;
procedure TForm1.seToleranceChange(Sender: TObject);
begin
ChartLog.LeftAxis.Intervals.Tolerance := seTolerance.Value;
FUserFrame := TUserFrame.Create(Self);
FUserFrame.Parent := tsUser;
FUserFrame.Align := alClient;
end;
end.

View File

@ -42,7 +42,7 @@
<PackageName Value="LCL"/>
</Item2>
</RequiredPackages>
<Units Count="2">
<Units Count="6">
<Unit0>
<Filename Value="chartsourcedemo.lpr"/>
<IsPartOfProject Value="True"/>
@ -50,11 +50,42 @@
<Unit1>
<Filename Value="main.pas"/>
<IsPartOfProject Value="True"/>
<ComponentName Value="Form1"/>
<ComponentName Value="MainForm"/>
<HasResources Value="True"/>
<ResourceBaseClass Value="Form"/>
<UnitName Value="Main"/>
</Unit1>
<Unit2>
<Filename Value="frmbasic.pas"/>
<IsPartOfProject Value="True"/>
<ComponentName Value="BasicFrame"/>
<HasResources Value="True"/>
<ResourceBaseClass Value="Frame"/>
<UnitName Value="frmBasic"/>
</Unit2>
<Unit3>
<Filename Value="frmstatistics.pas"/>
<IsPartOfProject Value="True"/>
<ComponentName Value="StatisticsFrame"/>
<HasResources Value="True"/>
<ResourceBaseClass Value="Frame"/>
<UnitName Value="frmStatistics"/>
</Unit3>
<Unit4>
<Filename Value="frmderivative.pas"/>
<IsPartOfProject Value="True"/>
<ComponentName Value="DerivativeFrame"/>
<HasResources Value="True"/>
<ResourceBaseClass Value="Frame"/>
<UnitName Value="frmDerivative"/>
</Unit4>
<Unit5>
<Filename Value="frmsorted.pas"/>
<IsPartOfProject Value="True"/>
<ComponentName Value="SortedFrame"/>
<ResourceBaseClass Value="Frame"/>
<UnitName Value="frmSorted"/>
</Unit5>
</Units>
</ProjectOptions>
<CompilerOptions>
@ -64,11 +95,6 @@
<IncludeFiles Value="$(ProjOutDir)"/>
<UnitOutputDirectory Value="lib\$(TargetCPU)-$(TargetOS)"/>
</SearchPaths>
<Parsing>
<SyntaxOptions>
<UseAnsiStrings Value="False"/>
</SyntaxOptions>
</Parsing>
<CodeGeneration>
<Checks>
<RangeChecks Value="True"/>
@ -77,6 +103,7 @@
</CodeGeneration>
<Linking>
<Debugging>
<DebugInfoType Value="dsDwarf3"/>
<UseExternalDbgSyms Value="True"/>
</Debugging>
<Options>

View File

@ -7,15 +7,14 @@ uses
cthreads,
{$ENDIF}{$ENDIF}
Interfaces, // this includes the LCL widgetset
Forms, Main, TAChartLazarusPkg
{ you can add units after this };
Forms, Main;
{$R *.res}
begin
Application.Scaled:=True;
Application.Initialize;
Application.CreateForm(TForm1, Form1);
Application.CreateForm(TMainForm, MainForm);
Application.Run;
end.

View File

@ -0,0 +1,130 @@
object BasicFrame: TBasicFrame
Left = 0
Height = 363
Top = 0
Width = 605
ClientHeight = 363
ClientWidth = 605
TabOrder = 0
DesignLeft = 592
DesignTop = 284
object Label1: TLabel
Left = 2
Height = 30
Top = 2
Width = 601
Align = alTop
BorderSpacing.Bottom = 4
BorderSpacing.Around = 2
Caption = 'Modify sources at design-time.'#13#10'Same-colored series from each chart have common sources.'
WordWrap = True
end
object Chart1: TChart
Left = 314
Height = 325
Top = 38
Width = 291
AxisList = <
item
Marks.LabelBrush.Style = bsClear
Minors = <>
Title.LabelFont.Orientation = 900
Title.LabelBrush.Style = bsClear
end
item
Alignment = calBottom
Marks.LabelBrush.Style = bsClear
Minors = <>
Title.LabelBrush.Style = bsClear
end>
Foot.Brush.Color = clBtnFace
Foot.Font.Color = clBlue
Title.Brush.Color = clBtnFace
Title.Font.Color = clBlue
Title.Text.Strings = (
'TAChart'
)
Align = alRight
Color = clDefault
object Chart1BarSeries1: TBarSeries
BarBrush.Color = clRed
Source = RandomChartSource1
end
object Chart1LineSeries1: TLineSeries
ZPosition = 1
LinePen.Color = clBlue
Pointer.Brush.Color = clBlue
Pointer.Visible = True
ShowPoints = True
Source = ListChartSource1
end
end
object Chart2: TChart
Left = 0
Height = 325
Top = 38
Width = 309
AxisList = <
item
Marks.LabelBrush.Style = bsClear
Minors = <>
Title.LabelFont.Orientation = 900
Title.LabelBrush.Style = bsClear
end
item
Alignment = calBottom
Marks.LabelBrush.Style = bsClear
Minors = <>
Title.LabelBrush.Style = bsClear
end>
Foot.Brush.Color = clBtnFace
Foot.Font.Color = clBlue
Title.Brush.Color = clBtnFace
Title.Font.Color = clBlue
Title.Text.Strings = (
'TAChart'
)
Align = alClient
Color = clDefault
object Chart2LineSeries1: TLineSeries
LinePen.Color = clRed
Pointer.Brush.Color = clRed
Pointer.Visible = True
ShowPoints = True
Source = RandomChartSource1
end
object Chart2AreaSeries1: TAreaSeries
AreaBrush.Color = clBlue
AreaLinesPen.Color = clMaroon
Source = ListChartSource1
end
end
object Splitter1: TSplitter
Left = 309
Height = 325
Top = 38
Width = 5
Align = alRight
ResizeAnchor = akRight
end
object RandomChartSource1: TRandomChartSource
PointsNumber = 8
RandSeed = 624484796
XMax = 5
XMin = -5
YMax = 10
Left = 116
Top = 140
end
object ListChartSource1: TListChartSource
DataPoints.Strings = (
'-3|2|?|'
'-2|3|?|'
'-1|4|?|'
'0|1|?|'
'3|2|?|'
)
Left = 116
Top = 196
end
end

View File

@ -0,0 +1,35 @@
unit frmBasic;
{$mode ObjFPC}{$H+}
interface
uses
SysUtils, Classes,
Forms, Controls, StdCtrls, ExtCtrls,
TAGraph, TASources, TASeries;
type
TBasicFrame = class(TFrame)
Chart1: TChart;
Chart1BarSeries1: TBarSeries;
Chart1LineSeries1: TLineSeries;
Chart2: TChart;
Chart2AreaSeries1: TAreaSeries;
Chart2LineSeries1: TLineSeries;
Label1: TLabel;
ListChartSource1: TListChartSource;
RandomChartSource1: TRandomChartSource;
Splitter1: TSplitter;
private
public
end;
implementation
{$R *.lfm}
end.

View File

@ -0,0 +1,183 @@
object DerivativeFrame: TDerivativeFrame
Left = 0
Height = 430
Top = 0
Width = 631
ClientHeight = 430
ClientWidth = 631
TabOrder = 0
DesignLeft = 314
DesignTop = 130
object ParamsPanel: TPanel
Left = 0
Height = 39
Top = 391
Width = 631
Align = alBottom
AutoSize = True
BevelOuter = bvNone
ClientHeight = 39
ClientWidth = 631
TabOrder = 0
object lblAccumulationRange: TLabel
AnchorSideLeft.Control = ParamsPanel
AnchorSideTop.Control = ParamsPanel
AnchorSideTop.Side = asrCenter
Left = 8
Height = 15
Top = 12
Width = 108
BorderSpacing.Left = 8
Caption = 'AccumulationRange'
end
object seAccumulationRange: TSpinEdit
AnchorSideLeft.Control = lblAccumulationRange
AnchorSideLeft.Side = asrBottom
AnchorSideTop.Control = ParamsPanel
AnchorSideTop.Side = asrCenter
Left = 124
Height = 23
Top = 8
Width = 74
Alignment = taRightJustify
BorderSpacing.Left = 8
MaxValue = 10000
TabOrder = 0
Value = 2
OnChange = seAccumulationRangeChange
end
object cbAccDirDerivative: TComboBox
AnchorSideLeft.Control = seAccumulationRange
AnchorSideLeft.Side = asrBottom
AnchorSideTop.Control = ParamsPanel
AnchorSideTop.Side = asrCenter
Left = 214
Height = 23
Top = 8
Width = 100
BorderSpacing.Left = 16
BorderSpacing.Top = 8
BorderSpacing.Bottom = 8
ItemHeight = 15
ItemIndex = 0
Items.Strings = (
'Backward'
'Forward'
'Center'
)
Style = csDropDownList
TabOrder = 1
Text = 'Backward'
OnChange = cbAccDirDerivativeChange
end
object cbSmooth: TCheckBox
AnchorSideLeft.Control = cbAccDirDerivative
AnchorSideLeft.Side = asrBottom
AnchorSideTop.Control = ParamsPanel
AnchorSideTop.Side = asrCenter
Left = 330
Height = 19
Top = 10
Width = 60
BorderSpacing.Left = 16
Caption = 'Smooth'
TabOrder = 2
OnChange = cbSmoothChange
end
end
object rgDataShape: TRadioGroup
Left = 6
Height = 51
Top = 340
Width = 619
Align = alBottom
AutoFill = True
AutoSize = True
BorderSpacing.Left = 6
BorderSpacing.Right = 6
Caption = 'Functions'
ChildSizing.LeftRightSpacing = 6
ChildSizing.TopBottomSpacing = 6
ChildSizing.HorizontalSpacing = 12
ChildSizing.EnlargeHorizontal = crsHomogenousChildResize
ChildSizing.EnlargeVertical = crsHomogenousChildResize
ChildSizing.ShrinkHorizontal = crsScaleChilds
ChildSizing.ShrinkVertical = crsScaleChilds
ChildSizing.Layout = cclLeftToRightThenTopToBottom
ChildSizing.ControlsPerLine = 7
ClientHeight = 31
ClientWidth = 615
Columns = 7
ItemIndex = 0
Items.Strings = (
'y = x'
'y = sin(x)'
'y = sin(x) / x'
'y = exp(-x/3)'
'Gaussian'
'Noisy Gaussian'
'Data from table'
)
ParentFont = False
TabOrder = 1
OnClick = rgDataShapeClick
end
object chDerivative: TChart
Left = 0
Height = 340
Top = 0
Width = 631
AxisList = <
item
Grid.Color = clSilver
Marks.LabelBrush.Style = bsClear
Minors = <>
Title.LabelFont.Orientation = 900
Title.Visible = True
Title.Caption = 'y, dy/dx'
Title.LabelBrush.Style = bsClear
end
item
Grid.Color = clSilver
Alignment = calBottom
Marks.LabelBrush.Style = bsClear
Minors = <>
Title.Visible = True
Title.Caption = 'x'
Title.LabelBrush.Style = bsClear
end>
BackColor = clWhite
Foot.Brush.Color = clBtnFace
Foot.Font.Color = clBlue
Legend.Alignment = laTopCenter
Legend.ColumnCount = 2
Legend.Visible = True
Title.Brush.Color = clBtnFace
Title.Font.Color = clBlue
Title.Text.Strings = (
'TAChart'
)
Align = alClient
Color = clWindow
DoubleBuffered = True
object chDerivativeLineOrig: TLineSeries
Title = 'y'
Source = lcsDerivative
end
object chDerivativeLineDeriv: TLineSeries
Title = 'dy/dx'
LinePen.Color = clRed
Source = ccsDerivative
end
end
object lcsDerivative: TListChartSource
Left = 112
Top = 64
end
object ccsDerivative: TCalculatedChartSource
AccumulationMethod = camDerivative
Origin = lcsDerivative
Left = 112
Top = 120
end
end

View File

@ -0,0 +1,101 @@
unit frmDerivative;
{$mode ObjFPC}{$H+}
interface
uses
SysUtils, Classes, Math,
Forms, Controls, StdCtrls, ExtCtrls, Spin,
TAGraph, TASeries, TASources;
type
TDerivativeFrame = class(TFrame)
cbAccDirDerivative: TComboBox;
cbSmooth: TCheckBox;
ccsDerivative: TCalculatedChartSource;
chDerivative: TChart;
chDerivativeLineDeriv: TLineSeries;
chDerivativeLineOrig: TLineSeries;
lblAccumulationRange: TLabel;
lcsDerivative: TListChartSource;
ParamsPanel: TPanel;
rgDataShape: TRadioGroup;
seAccumulationRange: TSpinEdit;
procedure cbAccDirDerivativeChange(Sender: TObject);
procedure cbSmoothChange(Sender: TObject);
procedure rgDataShapeClick(Sender: TObject);
procedure seAccumulationRangeChange(Sender: TObject);
private
procedure CreateDataForDerivative;
public
constructor Create(AOwner: TComponent); override;
end;
implementation
{$R *.lfm}
constructor TDerivativeFrame.Create(AOwner: TComponent);
begin
inherited;
CreateDataForDerivative;
end;
procedure TDerivativeFrame.cbAccDirDerivativeChange(Sender: TObject);
begin
ccsDerivative.AccumulationDirection := TChartAccumulationDirection(cbAccDirDerivative.ItemIndex);
end;
procedure TDerivativeFrame.cbSmoothChange(Sender: TObject);
begin
if cbSmooth.Checked then
ccsDerivative.AccumulationMethod := camSmoothDerivative
else
ccsDerivative.AccumulationMethod := camDerivative;
end;
procedure TDerivativeFrame.CreateDataForDerivative;
const
N = 100;
MIN_X = -10;
MAX_X = 10;
EPS = 1e-6;
var
i: Integer;
x, y: Double;
begin
lcsDerivative.Clear;
if rgDataShape.ItemIndex = 6 then
for i := 0 to 9 do
lcsDerivative.Add(i - IfThen(i > 6, 1, 0), i)
else
for i := 0 to N - 1 do begin
x := MIN_X + (MAX_X - MIN_X) / (N - 1) * i;
if SameValue(x, 0.0, EPS) then x := 0;
case rgDataShape.ItemIndex of
0: y := x;
1: y := Sin(x);
2: if x = 0 then y := 1 else y := Sin(x) / x;
3: y := Exp(-x / 3);
4: y := Exp(-Sqr((x - 2.5) / 2.5));
5: y := Exp(-Sqr((x - 2.5) / 2.5)) + 0.05 * (Random - 0.5);
end;
lcsDerivative.Add(x, y);
end;
end;
procedure TDerivativeFrame.rgDataShapeClick(Sender: TObject);
begin
CreateDataForDerivative;
end;
procedure TDerivativeFrame.seAccumulationRangeChange(Sender: TObject);
begin
ccsDerivative.AccumulationRange := seAccumulationRange.Value;
end;
end.

View File

@ -0,0 +1,109 @@
object SortedFrame: TSortedFrame
Left = 0
Height = 384
Top = 0
Width = 642
ClientHeight = 384
ClientWidth = 642
TabOrder = 0
DesignLeft = 502
DesignTop = 268
object btnSort: TButton
AnchorSideLeft.Control = Owner
Left = 8
Height = 25
Top = 8
Width = 227
AutoSize = True
BorderSpacing.Left = 8
BorderSpacing.Top = 8
Caption = 'Sort/unsort data by number of visitors'
TabOrder = 0
OnClick = btnSortClick
end
object lblSortInfo: TLabel
AnchorSideLeft.Control = btnSort
AnchorSideLeft.Side = asrBottom
AnchorSideTop.Control = btnSort
AnchorSideTop.Side = asrCenter
Left = 243
Height = 15
Top = 13
Width = 55
BorderSpacing.Left = 8
Caption = 'lblSortInfo'
end
object BubbleChart: TChart
AnchorSideLeft.Control = Owner
AnchorSideTop.Control = btnSort
AnchorSideTop.Side = asrBottom
AnchorSideRight.Control = Owner
AnchorSideRight.Side = asrBottom
AnchorSideBottom.Control = Owner
AnchorSideBottom.Side = asrBottom
Left = 8
Height = 335
Top = 41
Width = 626
AxisList = <
item
Visible = False
Marks.LabelBrush.Style = bsClear
Minors = <>
Title.LabelFont.Orientation = 900
Title.LabelBrush.Style = bsClear
end
item
Alignment = calBottom
Marks.Format = '%4:.9g'
Marks.LabelBrush.Style = bsClear
Marks.Source = SortedChartSource
Marks.Style = smsXValue
Minors = <>
Title.LabelBrush.Style = bsClear
end>
Foot.Brush.Color = clBtnFace
Foot.Font.Color = clBlue
Margins.Left = 20
Margins.Right = 40
Title.Brush.Color = clBtnFace
Title.Brush.Style = bsClear
Title.Font.Color = clBlue
Title.Text.Strings = (
'Locations of World Exposition X, and numbers of visitors (given by bubble size)'
)
Title.Visible = True
OnAfterPaint = BubbleChartAfterPaint
Anchors = [akTop, akLeft, akRight, akBottom]
BorderSpacing.Around = 8
Color = clWindow
object BubbleSeries: TBubbleSeries
AxisIndexX = 1
AxisIndexY = 0
BubbleRadiusUnits = bruY
MarkPositions = lmpPositive
Marks.Attachment = maCenter
Marks.Distance = 0
Marks.LabelFont.Orientation = 900
Marks.Format = '%2:s'
Marks.LabelBrush.Color = clWhite
Marks.Style = smsLabel
OverrideColor = [bocBrush]
Source = SortedChartSource
end
end
object UserDefinedChartSource: TUserDefinedChartSource
OnGetChartDataItem = UserDefinedChartSourceGetChartDataItem
YCount = 2
Left = 88
Top = 88
end
object SortedChartSource: TSortedChartSource
Origin = UserDefinedChartSource
SortBy = sbY
SortDir = sdDescending
SortIndex = 1
Left = 88
Top = 144
end
end

View File

@ -0,0 +1,105 @@
unit frmSorted;
{$mode ObjFPC}{$H+}
interface
uses
SysUtils, Classes,
Forms, Controls, StdCtrls,
TAGraph, TAChartUtils, TAMultiSeries, TACustomSource, TASources;
type
TDataForSorting = record
Year: Integer;
CityName: String;
Visitors: Integer;
Color: TChartColor;
end;
TSortedFrame = class(TFrame)
btnSort: TButton;
BubbleChart: TChart;
BubbleSeries: TBubbleSeries;
lblSortInfo: TLabel;
SortedChartSource: TSortedChartSource;
UserDefinedChartSource: TUserDefinedChartSource;
procedure btnSortClick(Sender: TObject);
procedure BubbleChartAfterPaint({%H-}ASender: TChart);
procedure UserDefinedChartSourceGetChartDataItem({%H-}ASource:
TUserDefinedChartSource; AIndex: Integer; var AItem: TChartDataItem);
private
FDataForSorting: array of TDataForSorting;
procedure CreateDataForSorting;
public
constructor Create(AOwner: TComponent); override;
end;
implementation
{$R *.lfm}
constructor TSortedFrame.Create(AOwner: TComponent);
begin
inherited;
CreateDataForSorting;
end;
procedure TSortedFrame.btnSortClick(Sender: TObject);
begin
SortedChartSource.Sorted := not SortedChartSource.Sorted;
end;
procedure TSortedFrame.BubbleChartAfterPaint(ASender: TChart);
begin
if SortedChartSource.IsSorted then
lblSortInfo.Caption := 'Sorted by radius (descending)'
else
lblSortInfo.Caption := 'Not sorted';
end;
procedure TSortedFrame.UserDefinedChartSourceGetChartDataItem(ASource:
TUserDefinedChartSource; AIndex: Integer; var AItem: TChartDataItem);
begin
AItem.X := FDataForSorting[AIndex].Year;
AItem.Y := 0;
AItem.YList[0] := Sqrt(FDataForSorting[AIndex].Visitors/100000 / PI);
AItem.Text := FDataForSorting[AIndex].CityName;
AItem.Color := FDataForSorting[AIndex].Color;
end;
procedure TSortedFrame.CreateDataForSorting;
procedure AddCity(AYear: Integer; const ACityName: string;
ANumberOfVisitors: Integer; AColor: TChartColor);
begin
SetLength(FDataForSorting, Length(FDataForSorting) + 1);
with FDataForSorting[High(FDataForSorting)] do begin
Year := AYear;
CityName := ACityName;
Visitors := ANumberOfVisitors;
Color := AColor;
end;
end;
begin
SetLength(FDataForSorting, 0);
AddCity(1967, 'City A', 155000, $00FFFF); // yellow
AddCity(1968, 'City B', 30000, $FF0000); // blue
AddCity(1969, 'City C', 450000, $FF00FF); // fuchsia
AddCity(1970, 'City D', 50000, $FFFF00); // aqua
AddCity(1971, 'City E', 80000, $00FF00); // lime
AddCity(1972, 'City F', 615000, $0000FF); // red
UserDefinedChartSource.PointsNumber := Length(FDataForSorting);
{ These settings are made in the Object Inspector for the SortedChartSource:
- Origin = UserDefinedChartSource
- SortBy = sbY
- SortIndex = 1 // --> sort by radius
- SortDir = sdDescending // --> draw large bubbles first
}
end;
end.

View File

@ -0,0 +1,139 @@
object StatisticsFrame: TStatisticsFrame
Left = 0
Height = 382
Top = 0
Width = 619
ClientHeight = 382
ClientWidth = 619
TabOrder = 0
DesignLeft = 538
DesignTop = 282
object chCalc: TChart
Left = 0
Height = 342
Top = 0
Width = 619
AxisList = <
item
Marks.LabelBrush.Style = bsClear
Minors = <>
Title.LabelFont.Orientation = 900
Title.LabelBrush.Style = bsClear
end
item
Alignment = calBottom
Marks.LabelBrush.Style = bsClear
Minors = <>
Title.LabelBrush.Style = bsClear
end>
Foot.Brush.Color = clBtnFace
Foot.Font.Color = clBlue
Legend.Alignment = laTopLeft
Legend.MarginX = 40
Legend.MarginY = 10
Legend.UseSidebar = False
Legend.Visible = True
Title.Brush.Color = clBtnFace
Title.Font.Color = clBlue
Title.Text.Strings = (
'TAChart'
)
Align = alClient
Color = clWindow
object chCalcLineSeries1: TLineSeries
Title = 'Data'
LineType = ltNone
Pointer.Visible = True
ShowPoints = True
Source = RandomChartSource2
end
object chCalcLineSeriesSum: TLineSeries
Title = 'Cumulative'
LinePen.Color = clMaroon
LinePen.Width = 2
Source = ccsSum
end
object chCalcLineSeriesAvg: TLineSeries
Title = 'Running average'
ZPosition = 1
LinePen.Color = clTeal
LinePen.Width = 2
Source = ccsAvg
end
end
object Panel2: TPanel
Left = 0
Height = 40
Top = 342
Width = 619
Align = alBottom
AutoSize = True
BevelOuter = bvNone
ClientHeight = 40
ClientWidth = 619
TabOrder = 1
object cbCumulative: TCheckBox
AnchorSideLeft.Control = Panel2
AnchorSideTop.Control = Panel2
AnchorSideTop.Side = asrCenter
Left = 8
Height = 19
Top = 11
Width = 79
BorderSpacing.Left = 8
Caption = 'Cumulative'
Checked = True
State = cbChecked
TabOrder = 0
OnChange = cbCumulativeChange
end
object cbAccDirStatistics: TComboBox
AnchorSideLeft.Control = cbCumulative
AnchorSideLeft.Side = asrBottom
AnchorSideTop.Control = Panel2
AnchorSideTop.Side = asrCenter
Left = 111
Height = 23
Top = 9
Width = 100
BorderSpacing.Left = 24
BorderSpacing.Top = 8
BorderSpacing.Bottom = 8
ItemHeight = 15
ItemIndex = 0
Items.Strings = (
'Backward'
'Forward'
'Center'
)
Style = csDropDownList
TabOrder = 1
Text = 'Backward'
OnChange = cbAccDirStatisticsChange
end
end
object RandomChartSource2: TRandomChartSource
PointsNumber = 25
RandSeed = 840176578
XMax = 20
XMin = -10
YMax = 8
YMin = 1
Left = 120
Top = 104
end
object ccsSum: TCalculatedChartSource
AccumulationMethod = camSum
AccumulationRange = 0
Origin = RandomChartSource2
Left = 120
Top = 160
end
object ccsAvg: TCalculatedChartSource
AccumulationMethod = camAverage
AccumulationRange = 5
Origin = RandomChartSource2
Left = 120
Top = 216
end
end

View File

@ -0,0 +1,51 @@
unit frmStatistics;
{$mode ObjFPC}{$H+}
interface
uses
SysUtils, Classes,
Forms, Controls, StdCtrls, ExtCtrls,
TAGraph, TASeries, TASources;
type
TStatisticsFrame = class(TFrame)
cbAccDirStatistics: TComboBox;
cbCumulative: TCheckBox;
ccsAvg: TCalculatedChartSource;
ccsSum: TCalculatedChartSource;
chCalc: TChart;
chCalcLineSeries1: TLineSeries;
chCalcLineSeriesAvg: TLineSeries;
chCalcLineSeriesSum: TLineSeries;
Panel2: TPanel;
RandomChartSource2: TRandomChartSource;
procedure cbAccDirStatisticsChange(Sender: TObject);
procedure cbCumulativeChange(Sender: TObject);
private
public
end;
implementation
{$R *.lfm}
procedure TStatisticsFrame.cbCumulativeChange(Sender: TObject);
begin
chCalcLineSeriesSum.Active := cbCumulative.Checked;
end;
procedure TStatisticsFrame.cbAccDirStatisticsChange(Sender: TObject);
var
dir: TChartAccumulationDirection;
begin
dir := TChartAccumulationDirection(cbAccDirStatistics.ItemIndex);
ccsAvg.AccumulationDirection := dir;
ccsSum.AccumulationDirection := dir;
end;
end.

View File

@ -1,14 +1,14 @@
object Form1: TForm1
object MainForm: TMainForm
Left = 342
Height = 438
Top = 199
Width = 640
Caption = 'Form1'
Caption = 'ChartSource Demo'
ClientHeight = 438
ClientWidth = 640
LCLVersion = '4.99.0.0'
OnCreate = FormCreate
LCLVersion = '2.3.0.0'
object PageControl1: TPageControl
object PageControl: TPageControl
Left = 0
Height = 438
Top = 0
@ -21,539 +21,23 @@ object Form1: TForm1
Caption = 'Basic'
ClientHeight = 410
ClientWidth = 632
object Chart2: TChart
Left = 0
Height = 372
Top = 38
Width = 336
AxisList = <
item
Marks.LabelBrush.Style = bsClear
Minors = <>
Title.LabelFont.Orientation = 900
Title.LabelBrush.Style = bsClear
end
item
Alignment = calBottom
Marks.LabelBrush.Style = bsClear
Minors = <>
Title.LabelBrush.Style = bsClear
end>
Foot.Brush.Color = clBtnFace
Foot.Font.Color = clBlue
Title.Brush.Color = clBtnFace
Title.Font.Color = clBlue
Title.Text.Strings = (
'TAChart'
)
Align = alClient
Color = clDefault
object Chart2LineSeries1: TLineSeries
LinePen.Color = clRed
Pointer.Brush.Color = clRed
Pointer.Visible = True
ShowPoints = True
Source = RandomChartSource1
end
object Chart2AreaSeries1: TAreaSeries
AreaBrush.Color = clBlue
AreaLinesPen.Color = clMaroon
Source = ListChartSource1
end
end
object Chart1: TChart
Left = 341
Height = 372
Top = 38
Width = 291
AxisList = <
item
Marks.LabelBrush.Style = bsClear
Minors = <>
Title.LabelFont.Orientation = 900
Title.LabelBrush.Style = bsClear
end
item
Alignment = calBottom
Marks.LabelBrush.Style = bsClear
Minors = <>
Title.LabelBrush.Style = bsClear
end>
Foot.Brush.Color = clBtnFace
Foot.Font.Color = clBlue
Title.Brush.Color = clBtnFace
Title.Font.Color = clBlue
Title.Text.Strings = (
'TAChart'
)
Align = alRight
Color = clDefault
object Chart1BarSeries1: TBarSeries
BarBrush.Color = clRed
Source = RandomChartSource1
end
object Chart1LineSeries1: TLineSeries
ZPosition = 1
LinePen.Color = clBlue
Pointer.Brush.Color = clBlue
Pointer.Visible = True
ShowPoints = True
Source = ListChartSource1
end
end
object Splitter1: TSplitter
Left = 336
Height = 372
Top = 38
Left = 627
Height = 410
Top = 0
Width = 5
Align = alRight
ResizeAnchor = akRight
end
object Label1: TLabel
Left = 2
Height = 30
Top = 2
Width = 628
Align = alTop
BorderSpacing.Bottom = 4
BorderSpacing.Around = 2
Caption = 'Modify sources at design-time.'#13#10'Same-colored series from each chart have common sources.'
WordWrap = True
end
end
object tsStatistics: TTabSheet
Caption = 'Statistics'
ClientHeight = 410
ClientWidth = 632
object chCalc: TChart
Left = 0
Height = 370
Top = 0
Width = 632
AxisList = <
item
Marks.LabelBrush.Style = bsClear
Minors = <>
Title.LabelFont.Orientation = 900
Title.LabelBrush.Style = bsClear
end
item
Alignment = calBottom
Marks.LabelBrush.Style = bsClear
Minors = <>
Title.LabelBrush.Style = bsClear
end>
Foot.Brush.Color = clBtnFace
Foot.Font.Color = clBlue
Legend.Alignment = laTopLeft
Legend.MarginX = 40
Legend.MarginY = 10
Legend.UseSidebar = False
Legend.Visible = True
Title.Brush.Color = clBtnFace
Title.Font.Color = clBlue
Title.Text.Strings = (
'TAChart'
)
Align = alClient
Color = clWindow
object chCalcLineSeries1: TLineSeries
Title = 'Data'
LineType = ltNone
Pointer.Visible = True
ShowPoints = True
Source = RandomChartSource2
end
object chCalcLineSeriesSum: TLineSeries
Title = 'Cumulative'
LinePen.Color = clMaroon
LinePen.Width = 2
Source = ccsSum
end
object chCalcLineSeriesAvg: TLineSeries
Title = 'Running average'
ZPosition = 1
LinePen.Color = clTeal
LinePen.Width = 2
Source = ccsAvg
end
end
object Panel2: TPanel
Left = 0
Height = 40
Top = 370
Width = 632
Align = alBottom
AutoSize = True
BevelOuter = bvNone
ClientHeight = 40
ClientWidth = 632
TabOrder = 1
object cbCumulative: TCheckBox
AnchorSideLeft.Control = Panel2
AnchorSideTop.Control = Panel2
AnchorSideTop.Side = asrCenter
Left = 8
Height = 19
Top = 11
Width = 79
BorderSpacing.Left = 8
Caption = 'Cumulative'
Checked = True
OnChange = cbCumulativeChange
State = cbChecked
TabOrder = 0
end
object cbAccDirStatistics: TComboBox
AnchorSideLeft.Control = cbCumulative
AnchorSideLeft.Side = asrBottom
AnchorSideTop.Control = Panel2
AnchorSideTop.Side = asrCenter
Left = 111
Height = 23
Top = 9
Width = 100
BorderSpacing.Left = 24
BorderSpacing.Top = 8
BorderSpacing.Bottom = 8
ItemHeight = 15
ItemIndex = 0
Items.Strings = (
'Backward'
'Forward'
'Center'
)
OnChange = cbAccDirStatisticsChange
Style = csDropDownList
TabOrder = 1
Text = 'Backward'
end
end
end
object tsDerivative: TTabSheet
Caption = 'Derivative'
ClientHeight = 410
ClientWidth = 632
object chDerivative: TChart
Left = 0
Height = 320
Top = 0
Width = 632
AxisList = <
item
Grid.Color = clSilver
Marks.LabelBrush.Style = bsClear
Minors = <>
Title.LabelFont.Orientation = 900
Title.Visible = True
Title.Caption = 'y, dy/dx'
Title.LabelBrush.Style = bsClear
end
item
Grid.Color = clSilver
Alignment = calBottom
Marks.LabelBrush.Style = bsClear
Minors = <>
Title.Visible = True
Title.Caption = 'x'
Title.LabelBrush.Style = bsClear
end>
BackColor = clWhite
Foot.Brush.Color = clBtnFace
Foot.Font.Color = clBlue
Legend.Alignment = laTopCenter
Legend.ColumnCount = 2
Legend.Visible = True
Title.Brush.Color = clBtnFace
Title.Font.Color = clBlue
Title.Text.Strings = (
'TAChart'
)
Align = alClient
Color = clWindow
DoubleBuffered = True
object chDerivativeLineOrig: TLineSeries
Title = 'y'
Source = lcsDerivative
end
object chDerivativeLineDeriv: TLineSeries
Title = 'dy/dx'
LinePen.Color = clRed
Source = ccsDerivative
end
end
object rgDataShape: TRadioGroup
Left = 6
Height = 51
Top = 320
Width = 620
Align = alBottom
AutoFill = True
AutoSize = True
BorderSpacing.Left = 6
BorderSpacing.Right = 6
Caption = 'Functions'
ChildSizing.LeftRightSpacing = 6
ChildSizing.TopBottomSpacing = 6
ChildSizing.HorizontalSpacing = 12
ChildSizing.EnlargeHorizontal = crsHomogenousChildResize
ChildSizing.EnlargeVertical = crsHomogenousChildResize
ChildSizing.ShrinkHorizontal = crsScaleChilds
ChildSizing.ShrinkVertical = crsScaleChilds
ChildSizing.Layout = cclLeftToRightThenTopToBottom
ChildSizing.ControlsPerLine = 7
ClientHeight = 31
ClientWidth = 616
Columns = 7
ItemIndex = 0
Items.Strings = (
'y = x'
'y = sin(x)'
'y = sin(x) / x'
'y = exp(-x/3)'
'Gaussian'
'Noisy Gaussian'
'Data from table'
)
OnClick = rgDataShapeClick
ParentFont = False
TabOrder = 1
end
object Panel1: TPanel
Left = 0
Height = 39
Top = 371
Width = 632
Align = alBottom
AutoSize = True
BevelOuter = bvNone
ClientHeight = 39
ClientWidth = 632
TabOrder = 2
object lblAccumulationRange: TLabel
AnchorSideLeft.Control = Panel1
AnchorSideTop.Control = Panel1
AnchorSideTop.Side = asrCenter
Left = 8
Height = 15
Top = 12
Width = 108
BorderSpacing.Left = 8
Caption = 'AccumulationRange'
end
object seAccumulationRange: TSpinEdit
AnchorSideLeft.Control = lblAccumulationRange
AnchorSideLeft.Side = asrBottom
AnchorSideTop.Control = Panel1
AnchorSideTop.Side = asrCenter
Left = 124
Height = 23
Top = 8
Width = 74
Alignment = taRightJustify
BorderSpacing.Left = 8
MaxValue = 10000
OnChange = seAccumulationRangeChange
TabOrder = 0
Value = 2
end
object cbAccDirDerivative: TComboBox
AnchorSideLeft.Control = seAccumulationRange
AnchorSideLeft.Side = asrBottom
AnchorSideTop.Control = Panel1
AnchorSideTop.Side = asrCenter
Left = 214
Height = 23
Top = 8
Width = 100
BorderSpacing.Left = 16
BorderSpacing.Top = 8
BorderSpacing.Bottom = 8
ItemHeight = 15
ItemIndex = 0
Items.Strings = (
'Backward'
'Forward'
'Center'
)
OnChange = cbAccDirDerivativeChange
Style = csDropDownList
TabOrder = 1
Text = 'Backward'
end
object cbSmooth: TCheckBox
AnchorSideLeft.Control = cbAccDirDerivative
AnchorSideLeft.Side = asrBottom
AnchorSideTop.Control = Panel1
AnchorSideTop.Side = asrCenter
Left = 330
Height = 19
Top = 10
Width = 60
BorderSpacing.Left = 16
Caption = 'Smooth'
OnChange = cbSmoothChange
TabOrder = 2
end
end
end
object tsSorted: TTabSheet
Caption = 'Sorted'
ClientHeight = 410
ClientWidth = 632
object btnSort: TButton
AnchorSideLeft.Control = tsSorted
AnchorSideTop.Control = tsSorted
Left = 8
Height = 25
Top = 8
Width = 230
AutoSize = True
BorderSpacing.Left = 8
BorderSpacing.Top = 8
Caption = 'Sort/unsort data by number of visitors!'
OnClick = btnSortClick
TabOrder = 0
end
object BubbleChart: TChart
AnchorSideLeft.Control = tsSorted
AnchorSideTop.Control = btnSort
AnchorSideTop.Side = asrBottom
AnchorSideRight.Control = tsSorted
AnchorSideRight.Side = asrBottom
AnchorSideBottom.Control = tsSorted
AnchorSideBottom.Side = asrBottom
Left = 8
Height = 361
Top = 41
Width = 616
AxisList = <
item
Visible = False
Marks.LabelBrush.Style = bsClear
Minors = <>
Title.LabelFont.Orientation = 900
Title.LabelBrush.Style = bsClear
end
item
Alignment = calBottom
Marks.Format = '%4:.9g'
Marks.LabelBrush.Style = bsClear
Marks.Source = SortedChartSource
Marks.Style = smsXValue
Minors = <>
Title.LabelBrush.Style = bsClear
end>
Foot.Brush.Color = clBtnFace
Foot.Font.Color = clBlue
Margins.Left = 20
Margins.Right = 40
Title.Brush.Color = clBtnFace
Title.Brush.Style = bsClear
Title.Font.Color = clBlue
Title.Text.Strings = (
'Locations of World Exposition X, and numbers of visitors (given by bubble size)'
)
Title.Visible = True
OnAfterPaint = BubbleChartAfterPaint
Anchors = [akTop, akLeft, akRight, akBottom]
BorderSpacing.Around = 8
Color = clWindow
object BubbleSeries: TBubbleSeries
AxisIndexX = 1
AxisIndexY = 0
BubbleRadiusUnits = bruY
MarkPositions = lmpPositive
Marks.Attachment = maCenter
Marks.Distance = 0
Marks.LabelFont.Orientation = 900
Marks.Format = '%2:s'
Marks.LabelBrush.Color = clWhite
Marks.Style = smsLabel
OverrideColor = [bocBrush]
Source = SortedChartSource
end
end
object lblSortInfo: TLabel
AnchorSideLeft.Control = btnSort
AnchorSideLeft.Side = asrBottom
AnchorSideTop.Control = btnSort
AnchorSideTop.Side = asrCenter
Left = 246
Height = 15
Top = 13
Width = 55
BorderSpacing.Left = 8
Caption = 'lblSortInfo'
end
end
end
object RandomChartSource1: TRandomChartSource
PointsNumber = 8
RandSeed = 624484796
XMax = 5
XMin = -5
YMax = 10
Left = 88
Top = 112
end
object ListChartSource1: TListChartSource
DataPoints.Strings = (
'-3|2|?|'
'-2|3|?|'
'-1|4|?|'
'0|1|?|'
'3|2|?|'
)
Left = 88
Top = 168
end
object ccsSum: TCalculatedChartSource
AccumulationMethod = camSum
AccumulationRange = 0
Origin = RandomChartSource2
Left = 240
Top = 168
end
object ccsAvg: TCalculatedChartSource
AccumulationMethod = camAverage
AccumulationRange = 5
Origin = RandomChartSource2
Left = 240
Top = 224
end
object RandomChartSource2: TRandomChartSource
PointsNumber = 25
RandSeed = 840176578
XMax = 20
XMin = -10
YMax = 8
YMin = 1
Left = 240
Top = 112
end
object lcsDerivative: TListChartSource
Left = 376
Top = 112
end
object ccsDerivative: TCalculatedChartSource
AccumulationMethod = camDerivative
Origin = lcsDerivative
Left = 376
Top = 168
end
object UserDefinedChartSource: TUserDefinedChartSource
OnGetChartDataItem = UserDefinedChartSourceGetChartDataItem
YCount = 2
Left = 528
Top = 112
end
object SortedChartSource: TSortedChartSource
Origin = UserDefinedChartSource
SortBy = sbY
SortDir = sdDescending
SortIndex = 1
Left = 528
Top = 168
end
end

View File

@ -5,220 +5,57 @@ unit Main;
interface
uses
Classes, StdCtrls, ComCtrls, ExtCtrls, Spin, Forms,
TAGraph, TASeries, TACustomSource, TASources, TAMultiSeries, TAChartUtils;
Classes,
Forms, Controls, ExtCtrls, ComCtrls,
frmBasic, frmStatistics, frmDerivative, frmSorted;
type
TDataForSorting = record
Year: Integer;
CityName: String;
Visitors: Integer;
Color: TChartColor;
end;
{ TForm1 }
{ TMainForm }
TForm1 = class(TForm)
btnSort: TButton;
BubbleSeries: TBubbleSeries;
cbAccDirDerivative: TComboBox;
ccsDerivative: TCalculatedChartSource;
cbCumulative: TCheckBox;
ccsAvg: TCalculatedChartSource;
ccsSum: TCalculatedChartSource;
Chart1: TChart;
Chart1BarSeries1: TBarSeries;
Chart1LineSeries1: TLineSeries;
BubbleChart: TChart;
chDerivativeLineOrig: TLineSeries;
chDerivativeLineDeriv: TLineSeries;
Chart1LineSeries4: TLineSeries;
Chart1LineSeries5: TLineSeries;
Chart2: TChart;
Chart2AreaSeries1: TAreaSeries;
Chart2LineSeries1: TLineSeries;
chDerivative: TChart;
chCalc: TChart;
chCalcLineSeries1: TLineSeries;
chCalcLineSeriesAvg: TLineSeries;
chCalcLineSeriesSum: TLineSeries;
cbAccDirStatistics: TComboBox;
cbSmooth: TCheckBox;
Label1: TLabel;
lblSortInfo: TLabel;
seAccumulationRange: TSpinEdit;
lblAccumulationRange: TLabel;
ListChartSource1: TListChartSource;
lcsDerivative: TListChartSource;
PageControl1: TPageControl;
Panel1: TPanel;
Panel2: TPanel;
rgDataShape: TRadioGroup;
RandomChartSource1: TRandomChartSource;
RandomChartSource2: TRandomChartSource;
SortedChartSource: TSortedChartSource;
TMainForm = class(TForm)
PageControl: TPageControl;
Splitter1: TSplitter;
tsSorted: TTabSheet;
tsDerivative: TTabSheet;
tsStatistics: TTabSheet;
tsBasic: TTabSheet;
UserDefinedChartSource: TUserDefinedChartSource;
procedure btnSortClick(Sender: TObject);
procedure BubbleChartAfterPaint({%H-}ASender: TChart);
procedure cbAccDirDerivativeChange(Sender: TObject);
procedure cbAccDirStatisticsChange(Sender: TObject);
procedure cbCumulativeChange(Sender: TObject);
procedure cbSmoothChange(Sender: TObject);
procedure CreateDataForDerivative;
procedure CreateDataForSorting;
procedure seAccumulationRangeChange(Sender: TObject);
procedure FormCreate(Sender: TObject);
procedure rgDataShapeClick(Sender: TObject);
procedure UserDefinedChartSourceGetChartDataItem(
{%H-}ASource: TUserDefinedChartSource; AIndex: Integer;
var AItem: TChartDataItem);
private
FDataForSorting: array of TDataForSorting;
FBasicFrame: TBasicFrame;
FStatisticsFrame: TStatisticsFrame;
FDerivativeFrame: TDerivativeFrame;
FSortedFrame: TSortedFrame;
end;
var
Form1: TForm1;
MainForm: TMainForm;
implementation
{$R *.lfm}
uses
Math;
{ TMainForm }
{ TForm1 }
procedure TForm1.cbAccDirDerivativeChange(Sender: TObject);
begin
ccsDerivative.AccumulationDirection :=
TChartAccumulationDirection(cbAccDirDerivative.ItemIndex);
end;
procedure TForm1.btnSortClick(Sender: TObject);
begin
SortedChartSource.Sorted := not SortedChartSource.Sorted;
end;
procedure TForm1.BubbleChartAfterPaint(ASender: TChart);
begin
if SortedChartSource.IsSorted then
lblSortInfo.Caption := 'Sorted by radius (descending)'
else
lblSortInfo.Caption := 'Not sorted';
end;
procedure TForm1.cbAccDirStatisticsChange(Sender: TObject);
begin
ccsAvg.AccumulationDirection :=
TChartAccumulationDirection(cbAccDirStatistics.ItemIndex);
ccsSum.AccumulationDirection := ccsAvg.AccumulationDirection;
end;
procedure TForm1.cbCumulativeChange(Sender: TObject);
begin
chCalcLineSeriesSum.Active := cbCumulative.Checked;
end;
procedure TForm1.cbSmoothChange(Sender: TObject);
begin
if cbSmooth.Checked then
ccsDerivative.AccumulationMethod := camSmoothDerivative
else
ccsDerivative.AccumulationMethod := camDerivative;
end;
procedure TForm1.CreateDataForDerivative;
const
N = 100;
MIN_X = -10;
MAX_X = 10;
EPS = 1e-6;
var
i: Integer;
x, y: Double;
begin
lcsDerivative.Clear;
if rgDataShape.ItemIndex = 6 then
for i := 0 to 9 do
lcsDerivative.Add(i - IfThen(i > 6, 1, 0), i)
else
for i := 0 to N - 1 do begin
x := MIN_X + (MAX_X - MIN_X) / (N - 1) * i;
if SameValue(x, 0.0, EPS) then x := 0;
case rgDataShape.ItemIndex of
0: y := x;
1: y := Sin(x);
2: if x = 0 then y := 1 else y := Sin(x) / x;
3: y := Exp(-x / 3);
4: y := Exp(-Sqr((x - 2.5) / 2.5));
5: y := Exp(-Sqr((x - 2.5) / 2.5)) + 0.05 * (Random - 0.5);
end;
lcsDerivative.Add(x, y);
end;
end;
procedure TForm1.CreateDataForSorting;
procedure AddCity(AYear: Integer; const ACityName: string;
ANumberOfVisitors: Integer; AColor: TChartColor);
begin
SetLength(FDataForSorting, Length(FDataForSorting) + 1);
with FDataForSorting[High(FDataForSorting)] do begin
Year := AYear;
CityName := ACityName;
Visitors := ANumberOfVisitors;
Color := AColor;
end;
end;
begin
SetLength(FDataForSorting, 0);
AddCity(1967, 'City A', 155000, $00FFFF); // yellow
AddCity(1968, 'City B', 30000, $FF0000); // blue
AddCity(1969, 'City C', 450000, $FF00FF); // fuchsia
AddCity(1970, 'City D', 50000, $FFFF00); // aqua
AddCity(1971, 'City E', 80000, $00FF00); // lime
AddCity(1972, 'City F', 615000, $0000FF); // red
UserDefinedChartSource.PointsNumber := Length(FDataForSorting);
{ These settings are made in the Object Inspector for the SortedChartSource:
- Origin = UserDefinedChartSource
- SortBy = sbY
- SortIndex = 1 // --> sort by radius
- SortDir = sdDescending // --> draw large bubbles first
}
end;
procedure TForm1.FormCreate(Sender: TObject);
procedure TMainForm.FormCreate(Sender: TObject);
begin
Randomize;
CreateDataForDerivative;
CreateDataForSorting;
end;
procedure TForm1.rgDataShapeClick(Sender: TObject);
begin
CreateDataForDerivative;
end;
FBasicFrame := TBasicFrame.Create(self);
FBasicFrame.Parent := tsBasic;
FBasicFrame.Align := alClient;
procedure TForm1.UserDefinedChartSourceGetChartDataItem(
ASource: TUserDefinedChartSource; AIndex: Integer; var AItem: TChartDataItem);
begin
AItem.X := FDataForSorting[AIndex].Year;
AItem.Y := 0;
AItem.YList[0] := Sqrt(FDataForSorting[AIndex].Visitors/100000 / PI);
AItem.Text := FDataForSorting[AIndex].CityName;
AItem.Color := FDataForSorting[AIndex].Color;
end;
FStatisticsFrame := TStatisticsFrame.Create(self);
FStatisticsFrame.Parent := tsStatistics;
FStatisticsFrame.Align := alClient;
procedure TForm1.seAccumulationRangeChange(Sender: TObject);
begin
ccsDerivative.AccumulationRange := seAccumulationRange.Value;
FDerivativeFrame := TDerivativeFrame.Create(self);
FDerivativeFrame.Parent := tsDerivative;
FDerivativeFrame.Align := alClient;
FSortedFrame := TSortedFrame.Create(self);
FSortedFrame.Parent := tsSorted;
FSortedFrame.Align := alClient;
end;
end.