TAChart: Add "fit" page to the "distance" demo. Based on demo by Werner Pamler.

git-svn-id: trunk@38951 -
This commit is contained in:
ask 2012-10-02 14:37:12 +00:00
parent 5f293d23ae
commit 1b11439a5b
2 changed files with 523 additions and 315 deletions

View File

@ -1,327 +1,435 @@
object Form1: TForm1
Left = 495
Height = 531
Height = 590
Top = 225
Width = 800
Width = 803
Caption = 'Form1'
ClientHeight = 531
ClientWidth = 800
ClientHeight = 590
ClientWidth = 803
OnCreate = FormCreate
LCLVersion = '1.1'
object Chart1: TChart
object PageControl1: TPageControl
Left = 0
Height = 367
Height = 590
Top = 0
Width = 800
AutoFocus = True
AxisList = <
item
TickColor = clBlue
AxisPen.Color = clBlue
AxisPen.Visible = True
Marks.LabelFont.Color = clBlue
Minors = <>
Title.LabelFont.Orientation = 900
Transformations = ChartAxisTransformations1
end
item
Alignment = calBottom
Minors = <>
end
item
Grid.Visible = False
TickColor = clTeal
Alignment = calRight
AxisPen.Color = clTeal
AxisPen.Visible = True
Marks.LabelFont.Color = clTeal
Minors = <>
Transformations = ChartAxisTransformations3
end>
BackColor = clCream
Foot.Brush.Color = clBtnFace
Foot.Font.Color = clBlue
MarginsExternal.Left = 8
MarginsExternal.Top = 8
MarginsExternal.Right = 8
MarginsExternal.Bottom = 8
Title.Brush.Color = clBtnFace
Title.Font.Color = clBlue
Title.Text.Strings = (
'TAChart'
)
Toolset = ctDist
Width = 803
ActivePage = tsMain
Align = alClient
DoubleBuffered = True
ParentColor = False
object Chart1LineSeries1: TLineSeries
AxisIndexX = 1
AxisIndexY = 0
LinePen.Color = clBlue
Source = RandomChartSource1
TabIndex = 0
TabOrder = 0
object tsMain: TTabSheet
Caption = 'Main'
ClientHeight = 564
ClientWidth = 795
object StatusBar1: TStatusBar
Left = 0
Height = 20
Top = 544
Width = 795
Panels = <>
end
object Panel2: TPanel
Left = 0
Height = 36
Top = 508
Width = 795
Align = alBottom
BevelOuter = bvNone
Caption = 'Left-drag --> measure 1st distance, Shift to zoom while dragging Ctrl+left-drag --> measure 2nd distance Right-drag --> show values'
Color = clGray
Font.Color = clWhite
ParentColor = False
ParentFont = False
TabOrder = 1
end
object Panel1: TPanel
Left = 0
Height = 108
Top = 400
Width = 795
Align = alBottom
BevelOuter = bvNone
ClientHeight = 108
ClientWidth = 795
TabOrder = 2
object rgSnapMode: TRadioGroup
Left = 8
Height = 101
Top = 5
Width = 96
AutoFill = True
Caption = 'Snapping mode'
ChildSizing.LeftRightSpacing = 6
ChildSizing.TopBottomSpacing = 6
ChildSizing.EnlargeHorizontal = crsHomogenousChildResize
ChildSizing.EnlargeVertical = crsHomogenousChildResize
ChildSizing.ShrinkHorizontal = crsScaleChilds
ChildSizing.ShrinkVertical = crsScaleChilds
ChildSizing.Layout = cclLeftToRightThenTopToBottom
ChildSizing.ControlsPerLine = 1
ClientHeight = 83
ClientWidth = 92
ItemIndex = 0
Items.Strings = (
'cdmXY'
'cdmOnlyX'
'cdmOnlyY'
)
OnClick = rgSnapModeClick
TabOrder = 0
end
object rgDrawingMode: TRadioGroup
Left = 208
Height = 101
Top = 5
Width = 97
AutoFill = True
Caption = 'Drawing mode'
ChildSizing.LeftRightSpacing = 6
ChildSizing.TopBottomSpacing = 6
ChildSizing.EnlargeHorizontal = crsHomogenousChildResize
ChildSizing.EnlargeVertical = crsHomogenousChildResize
ChildSizing.ShrinkHorizontal = crsScaleChilds
ChildSizing.ShrinkVertical = crsScaleChilds
ChildSizing.Layout = cclLeftToRightThenTopToBottom
ChildSizing.ControlsPerLine = 1
ClientHeight = 83
ClientWidth = 93
ItemIndex = 1
Items.Strings = (
'tdmDefault'
'tdmNormal'
'tdmXor'
)
OnClick = rgDrawingModeClick
TabOrder = 1
end
object cbRotateLabel: TCheckBox
Left = 428
Height = 17
Top = 29
Width = 78
Caption = 'Rotate label'
Checked = True
OnClick = cbRotateLabelClick
State = cbChecked
TabOrder = 2
end
object cbShowLabel: TCheckBox
Left = 428
Height = 17
Top = 5
Width = 71
Caption = 'Show label'
Checked = True
OnClick = cbShowLabelClick
State = cbChecked
TabOrder = 3
end
object clrPenColor: TColorButton
Left = 708
Height = 25
Top = 41
Width = 78
BorderWidth = 2
ButtonColorAutoSize = False
ButtonColorSize = 16
ButtonColor = clBlack
Caption = 'Pen'
Margin = 4
OnColorChanged = clrPenColorColorChanged
end
object clrFontColor: TColorButton
Left = 708
Height = 25
Top = 70
Width = 78
BorderWidth = 2
ButtonColorAutoSize = False
ButtonColorSize = 16
ButtonColor = clBlack
Caption = 'Font'
Margin = 4
OnColorChanged = clrFontColorColorChanged
end
object clrBackgroundColor: TColorButton
Left = 708
Height = 25
Top = 8
Width = 78
BorderWidth = 2
ButtonColorAutoSize = False
ButtonColorSize = 16
ButtonColor = clBtnFace
Caption = 'Backgr'
Margin = 4
OnColorChanged = clrBackgroundColorColorChanged
end
object edEndbarLength: TSpinEdit
Left = 628
Height = 21
Top = 5
Width = 50
MaxValue = 1000
OnChange = edEndbarLengthChange
TabOrder = 4
Value = 1000
end
object lblEndBarLength: TLabel
Left = 548
Height = 13
Top = 8
Width = 67
Caption = 'Endbar length'
ParentColor = False
end
object cbHide: TCheckBox
Left = 428
Height = 17
Top = 81
Width = 103
Caption = 'Hide at mouse up'
OnClick = cbHideClick
TabOrder = 5
end
object rgMeasureMode: TRadioGroup
Left = 108
Height = 101
Top = 5
Width = 97
AutoFill = True
Caption = 'Measure mode'
ChildSizing.LeftRightSpacing = 6
ChildSizing.TopBottomSpacing = 6
ChildSizing.EnlargeHorizontal = crsHomogenousChildResize
ChildSizing.EnlargeVertical = crsHomogenousChildResize
ChildSizing.ShrinkHorizontal = crsScaleChilds
ChildSizing.ShrinkVertical = crsScaleChilds
ChildSizing.Layout = cclLeftToRightThenTopToBottom
ChildSizing.ControlsPerLine = 1
ClientHeight = 83
ClientWidth = 93
ItemIndex = 0
Items.Strings = (
'cdmXY'
'cdmOnlyX'
'cdmOnlyY'
)
OnClick = rgMeasureModeClick
TabOrder = 6
end
object mDistanceText: TMemo
Left = 536
Height = 53
Top = 42
Width = 138
Lines.Strings = (
'axis dist = %0:.4g'
'graph dist = %1:.4g'
)
OnChange = mDistanceTextChange
TabOrder = 7
end
object rgDataPointMode: TRadioGroup
Left = 308
Height = 101
Top = 5
Width = 97
AutoFill = True
Caption = 'Data point mode'
ChildSizing.LeftRightSpacing = 6
ChildSizing.TopBottomSpacing = 6
ChildSizing.EnlargeHorizontal = crsHomogenousChildResize
ChildSizing.EnlargeVertical = crsHomogenousChildResize
ChildSizing.ShrinkHorizontal = crsScaleChilds
ChildSizing.ShrinkVertical = crsScaleChilds
ChildSizing.Layout = cclLeftToRightThenTopToBottom
ChildSizing.ControlsPerLine = 1
ClientHeight = 83
ClientWidth = 93
ItemIndex = 0
Items.Strings = (
'Free'
'Snap'
'Lock'
)
OnClick = rgDataPointModeClick
TabOrder = 8
end
object cbFlipLabel: TCheckBox
Left = 428
Height = 17
Top = 53
Width = 61
Caption = 'Flip label'
OnClick = cbFlipLabelClick
TabOrder = 9
end
end
object Chart1: TChart
Left = 0
Height = 400
Top = 0
Width = 795
AutoFocus = True
AxisList = <
item
TickColor = clBlue
AxisPen.Color = clBlue
AxisPen.Visible = True
Marks.LabelFont.Color = clBlue
Minors = <>
Title.LabelFont.Orientation = 900
Transformations = ChartAxisTransformations1
end
item
Alignment = calBottom
Minors = <>
end
item
Grid.Visible = False
TickColor = clTeal
Alignment = calRight
AxisPen.Color = clTeal
AxisPen.Visible = True
Marks.LabelFont.Color = clTeal
Minors = <>
Transformations = ChartAxisTransformations3
end>
BackColor = clCream
Foot.Brush.Color = clBtnFace
Foot.Font.Color = clBlue
MarginsExternal.Left = 8
MarginsExternal.Top = 8
MarginsExternal.Right = 8
MarginsExternal.Bottom = 8
Title.Brush.Color = clBtnFace
Title.Font.Color = clBlue
Title.Text.Strings = (
'TAChart'
)
Toolset = ctDist
Align = alClient
DoubleBuffered = True
ParentColor = False
object Chart1LineSeries1: TLineSeries
AxisIndexX = 1
AxisIndexY = 0
LinePen.Color = clBlue
Source = RandomChartSource1
end
object Chart1LineSeries2: TLineSeries
AxisIndexX = 1
AxisIndexY = 0
LinePen.Color = clBlue
LinePen.Style = psDash
Source = RandomChartSource2
end
object Chart1LineSeries3: TLineSeries
AxisIndexX = 1
AxisIndexY = 2
LinePen.Color = clTeal
LinePen.Width = 3
Pointer.Brush.Color = clMoneyGreen
Pointer.Style = psCircle
ShowPoints = True
Source = RandomChartSource3
end
end
end
object Chart1LineSeries2: TLineSeries
AxisIndexX = 1
AxisIndexY = 0
LinePen.Color = clBlue
LinePen.Style = psDash
Source = RandomChartSource2
object tsFit: TTabSheet
Caption = 'Fit'
ClientHeight = 564
ClientWidth = 795
object pnlFit: TPanel
Left = 0
Height = 66
Top = 0
Width = 795
Align = alTop
ClientHeight = 66
ClientWidth = 795
TabOrder = 0
object rgFitParamCount: TRadioGroup
Left = 12
Height = 50
Top = 6
Width = 450
AutoFill = True
Caption = 'Measure (by dragging right mouse button)'
ChildSizing.LeftRightSpacing = 6
ChildSizing.TopBottomSpacing = 6
ChildSizing.EnlargeHorizontal = crsHomogenousChildResize
ChildSizing.EnlargeVertical = crsHomogenousChildResize
ChildSizing.ShrinkHorizontal = crsScaleChilds
ChildSizing.ShrinkVertical = crsScaleChilds
ChildSizing.Layout = cclLeftToRightThenTopToBottom
ChildSizing.ControlsPerLine = 3
ClientHeight = 32
ClientWidth = 446
Columns = 3
ItemIndex = 0
Items.Strings = (
'Mean value'
'Slope'
'Find peak'
)
OnClick = rgFitParamCountClick
TabOrder = 0
end
object lblFit: TLabel
Left = 472
Height = 13
Top = 8
Width = 22
Caption = 'lblFit'
ParentColor = False
Visible = False
end
end
object chFit: TChart
Left = 0
Height = 498
Top = 66
Width = 795
AxisList = <
item
Minors = <>
Title.LabelFont.Orientation = 900
end
item
Alignment = calBottom
Minors = <>
end>
Foot.Brush.Color = clBtnFace
Foot.Font.Color = clBlue
Title.Brush.Color = clBtnFace
Title.Font.Color = clBlue
Title.Text.Strings = (
'TAChart'
)
Toolset = ctFit
Align = alClient
DoubleBuffered = True
ParentColor = False
object chFitLineSeries1: TLineSeries
LineType = ltNone
Pointer.Brush.Color = clRed
Pointer.HorizSize = 3
Pointer.VertSize = 3
ShowPoints = True
end
object chFitFitSeries1: TFitSeries
Active = False
FitRange.Min = 1
FitRange.UseMax = True
FitRange.UseMin = True
ParamCount = 1
Pen.Color = clLime
Pen.Width = 3
end
end
end
object Chart1LineSeries3: TLineSeries
AxisIndexX = 1
AxisIndexY = 2
LinePen.Color = clTeal
LinePen.Width = 3
Pointer.Brush.Color = clMoneyGreen
Pointer.Style = psCircle
ShowPoints = True
Source = RandomChartSource3
end
end
object Panel1: TPanel
Left = 0
Height = 108
Top = 367
Width = 800
Align = alBottom
BevelOuter = bvNone
ClientHeight = 108
ClientWidth = 800
TabOrder = 1
object rgSnapMode: TRadioGroup
Left = 8
Height = 101
Top = 5
Width = 96
AutoFill = True
Caption = 'Snapping mode'
ChildSizing.LeftRightSpacing = 6
ChildSizing.TopBottomSpacing = 6
ChildSizing.EnlargeHorizontal = crsHomogenousChildResize
ChildSizing.EnlargeVertical = crsHomogenousChildResize
ChildSizing.ShrinkHorizontal = crsScaleChilds
ChildSizing.ShrinkVertical = crsScaleChilds
ChildSizing.Layout = cclLeftToRightThenTopToBottom
ChildSizing.ControlsPerLine = 1
ClientHeight = 83
ClientWidth = 92
ItemIndex = 0
Items.Strings = (
'cdmXY'
'cdmOnlyX'
'cdmOnlyY'
)
OnClick = rgSnapModeClick
TabOrder = 0
end
object rgDrawingMode: TRadioGroup
Left = 208
Height = 101
Top = 5
Width = 97
AutoFill = True
Caption = 'Drawing mode'
ChildSizing.LeftRightSpacing = 6
ChildSizing.TopBottomSpacing = 6
ChildSizing.EnlargeHorizontal = crsHomogenousChildResize
ChildSizing.EnlargeVertical = crsHomogenousChildResize
ChildSizing.ShrinkHorizontal = crsScaleChilds
ChildSizing.ShrinkVertical = crsScaleChilds
ChildSizing.Layout = cclLeftToRightThenTopToBottom
ChildSizing.ControlsPerLine = 1
ClientHeight = 83
ClientWidth = 93
ItemIndex = 1
Items.Strings = (
'tdmDefault'
'tdmNormal'
'tdmXor'
)
OnClick = rgDrawingModeClick
TabOrder = 1
end
object cbRotateLabel: TCheckBox
Left = 428
Height = 17
Top = 29
Width = 78
Caption = 'Rotate label'
Checked = True
OnClick = cbRotateLabelClick
State = cbChecked
TabOrder = 2
end
object cbShowLabel: TCheckBox
Left = 428
Height = 17
Top = 5
Width = 71
Caption = 'Show label'
Checked = True
OnClick = cbShowLabelClick
State = cbChecked
TabOrder = 3
end
object clrPenColor: TColorButton
Left = 708
Height = 25
Top = 41
Width = 78
BorderWidth = 2
ButtonColorAutoSize = False
ButtonColorSize = 16
ButtonColor = clBlack
Caption = 'Pen'
Margin = 4
OnColorChanged = clrPenColorColorChanged
end
object clrFontColor: TColorButton
Left = 708
Height = 25
Top = 70
Width = 78
BorderWidth = 2
ButtonColorAutoSize = False
ButtonColorSize = 16
ButtonColor = clBlack
Caption = 'Font'
Margin = 4
OnColorChanged = clrFontColorColorChanged
end
object clrBackgroundColor: TColorButton
Left = 708
Height = 25
Top = 8
Width = 78
BorderWidth = 2
ButtonColorAutoSize = False
ButtonColorSize = 16
ButtonColor = clBtnFace
Caption = 'Backgr'
Margin = 4
OnColorChanged = clrBackgroundColorColorChanged
end
object edEndbarLength: TSpinEdit
Left = 628
Height = 21
Top = 5
Width = 50
MaxValue = 1000
OnChange = edEndbarLengthChange
TabOrder = 4
Value = 1000
end
object lblEndBarLength: TLabel
Left = 548
Height = 13
Top = 8
Width = 67
Caption = 'Endbar length'
ParentColor = False
end
object cbHide: TCheckBox
Left = 428
Height = 17
Top = 81
Width = 103
Caption = 'Hide at mouse up'
OnClick = cbHideClick
TabOrder = 5
end
object rgMeasureMode: TRadioGroup
Left = 108
Height = 101
Top = 5
Width = 97
AutoFill = True
Caption = 'Measure mode'
ChildSizing.LeftRightSpacing = 6
ChildSizing.TopBottomSpacing = 6
ChildSizing.EnlargeHorizontal = crsHomogenousChildResize
ChildSizing.EnlargeVertical = crsHomogenousChildResize
ChildSizing.ShrinkHorizontal = crsScaleChilds
ChildSizing.ShrinkVertical = crsScaleChilds
ChildSizing.Layout = cclLeftToRightThenTopToBottom
ChildSizing.ControlsPerLine = 1
ClientHeight = 83
ClientWidth = 93
ItemIndex = 0
Items.Strings = (
'cdmXY'
'cdmOnlyX'
'cdmOnlyY'
)
OnClick = rgMeasureModeClick
TabOrder = 6
end
object mDistanceText: TMemo
Left = 536
Height = 53
Top = 42
Width = 138
Lines.Strings = (
'axis dist = %0:.4g'
'graph dist = %1:.4g'
)
OnChange = mDistanceTextChange
TabOrder = 7
end
object rgDataPointMode: TRadioGroup
Left = 308
Height = 101
Top = 5
Width = 97
AutoFill = True
Caption = 'Data point mode'
ChildSizing.LeftRightSpacing = 6
ChildSizing.TopBottomSpacing = 6
ChildSizing.EnlargeHorizontal = crsHomogenousChildResize
ChildSizing.EnlargeVertical = crsHomogenousChildResize
ChildSizing.ShrinkHorizontal = crsScaleChilds
ChildSizing.ShrinkVertical = crsScaleChilds
ChildSizing.Layout = cclLeftToRightThenTopToBottom
ChildSizing.ControlsPerLine = 1
ClientHeight = 83
ClientWidth = 93
ItemIndex = 0
Items.Strings = (
'Free'
'Snap'
'Lock'
)
OnClick = rgDataPointModeClick
TabOrder = 8
end
object cbFlipLabel: TCheckBox
Left = 428
Height = 17
Top = 53
Width = 61
Caption = 'Flip label'
OnClick = cbFlipLabelClick
TabOrder = 9
end
end
object StatusBar1: TStatusBar
Left = 0
Height = 20
Top = 511
Width = 800
Panels = <>
end
object Panel2: TPanel
Left = 0
Height = 36
Top = 475
Width = 800
Align = alBottom
BevelOuter = bvNone
Caption = 'Left-drag --> measure 1st distance, Shift to zoom while dragging Ctrl+left-drag --> measure 2nd distance Right-drag --> show values'
Color = clGray
Font.Color = clWhite
ParentColor = False
ParentFont = False
TabOrder = 3
end
object RandomChartSource1: TRandomChartSource
PointsNumber = 100
@ -364,6 +472,7 @@ object Form1: TForm1
PointerStart.Brush.Style = bsClear
PointerStart.Pen.Color = clRed
PointerStart.VertSize = 1000
Transparency = 128
OnMeasure = ctDistance1Measure
end
object ctDistance2: TDataPointDistanceTool
@ -404,4 +513,23 @@ object Form1: TForm1
MinValue = 10
end
end
object ctFit: TChartToolset
left = 260
top = 192
object ctFitDataPointDistanceTool1: TDataPointDistanceTool
Shift = [ssRight]
DrawingMode = tdmNormal
LinePen.Visible = False
Marks.Format = '%0:.9g'
Marks.LinkPen.Visible = False
MeasureMode = cdmOnlyX
PointerEnd.VertSize = 10000
PointerStart.VertSize = 10000
OnGetDistanceText = ctFitDataPointDistanceTool1GetDistanceText
OnMeasure = ctFitDataPointDistanceTool1Measure
end
object ctFitZoomDragTool1: TZoomDragTool
Shift = [ssLeft]
end
end
end

View File

@ -7,7 +7,7 @@ interface
uses
Classes, SysUtils, FileUtil, Forms, Controls, Graphics, Dialogs, ExtCtrls,
StdCtrls, Spin, ComCtrls,
TAChartUtils, TATransformations, TAGraph, TASources, TASeries,
TAChartUtils, TAFuncSeries, TATransformations, TAGraph, TASources, TASeries,
TATools, TADataTools, types;
type
@ -27,6 +27,9 @@ type
ChartAxisTransformations1LogarithmAxisTransform1: TLogarithmAxisTransform;
ChartAxisTransformations3: TChartAxisTransformations;
ChartAxisTransformations3AutoScaleAxisTransform1: TAutoScaleAxisTransform;
chFit: TChart;
chFitFitSeries1: TFitSeries;
chFitLineSeries1: TLineSeries;
clrBackgroundColor: TColorButton;
clrFontColor: TColorButton;
clrPenColor: TColorButton;
@ -34,11 +37,18 @@ type
ctCrosshair: TDataPointCrosshairTool;
ctDistance1: TDataPointDistanceTool;
ctDistance2: TDataPointDistanceTool;
ctFit: TChartToolset;
ctFitDataPointDistanceTool1: TDataPointDistanceTool;
ctFitZoomDragTool1: TZoomDragTool;
edEndbarLength: TSpinEdit;
lblFit: TLabel;
lblEndBarLength: TLabel;
mDistanceText: TMemo;
PageControl1: TPageControl;
Panel1: TPanel;
Panel2: TPanel;
pnlFit: TPanel;
rgFitParamCount: TRadioGroup;
RandomChartSource1: TRandomChartSource;
RandomChartSource2: TRandomChartSource;
RandomChartSource3: TRandomChartSource;
@ -47,6 +57,8 @@ type
rgMeasureMode: TRadioGroup;
rgSnapMode: TRadioGroup;
StatusBar1: TStatusBar;
tsMain: TTabSheet;
tsFit: TTabSheet;
procedure cbFlipLabelClick(Sender: TObject);
procedure cbHideClick(Sender: TObject);
procedure cbRotateLabelClick(Sender: TObject);
@ -59,14 +71,20 @@ type
procedure ctDistance1BeforeKeyUp(ATool: TChartTool; APoint: TPoint);
procedure ctDistance1Measure(
ASender: TDataPointDistanceTool);
procedure ctFitDataPointDistanceTool1GetDistanceText(
ASender: TDataPointDistanceTool; var AText: String);
procedure ctFitDataPointDistanceTool1Measure(
ASender: TDataPointDistanceTool);
procedure edEndbarLengthChange(Sender: TObject);
procedure FormCreate(Sender: TObject);
procedure mDistanceTextChange(Sender: TObject);
procedure rgFitParamCountClick(Sender: TObject);
procedure rgDataPointModeClick(Sender: TObject);
procedure rgDrawingModeClick(Sender: TObject);
procedure rgMeasureModeClick(Sender: TObject);
procedure rgSnapModeClick(Sender: TObject);
private
procedure PrepareFitData;
procedure SwitchOptions(AOptions: TDataPointDistanceTool.TOptions; AOn: Boolean);
procedure UpdateButtons;
end;
@ -79,7 +97,7 @@ implementation
{$R *.lfm}
uses
TACustomSeries;
TACustomSeries, TAMath;
{ TForm1 }
@ -178,6 +196,40 @@ begin
]);
end;
procedure TForm1.ctFitDataPointDistanceTool1GetDistanceText(
ASender: TDataPointDistanceTool; var AText: String);
var
xmin, xmax: Double;
begin
xmin := ASender.PointStart.AxisPos.X;
xmax := ASender.PointEnd.AxisPos.X;
EnsureOrder(xmin, xmax);
with chFitFitSeries1.FitRange do begin
Min := xmin;
Max := xmax;
end;
case rgFitParamCount.ItemIndex of
0: AText := Format('Mean value: %f', [chFitFitSeries1.Param[0]]);
1: AText := Format('Slope: %f', [chFitFitSeries1.Param[1]]);
2:
with chFitFitSeries1 do
AText := Format('Peak at x=%f y=%f', [
-Param[1] / (2 * Param[2]),
Param[0] - Sqr(Param[1])/(4 * Param[2])
]);
end;
chFitFitSeries1.Active := true;
lblFit.Visible := true;
lblFit.Caption := AText;
end;
procedure TForm1.ctFitDataPointDistanceTool1Measure(
ASender: TDataPointDistanceTool);
begin
chFitFitSeries1.Active := false;
end;
procedure TForm1.edEndbarLengthChange(Sender: TObject);
begin
ctDistance1.PointerStart.VertSize := edEndbarLength.Value;
@ -191,6 +243,8 @@ begin
mDistanceTextChange(nil);
rgDataPointModeClick(nil);
rgDrawingModeClick(nil);
PrepareFitData;
end;
procedure TForm1.mDistanceTextChange(Sender: TObject);
@ -206,6 +260,27 @@ begin
end;
end;
procedure TForm1.PrepareFitData;
const
N = 50;
NOISE = 0.5;
var
i: Integer;
x, y: Double;
begin
for i := 0 to N - 1 do begin
x := -10 + 10 * i / (N - 1);
y := Sqr(x) * 0.1 + 1;
chFitLineSeries1.AddXY(x, y + (Random - 1) * NOISE);
end;
for i := 0 to N - 1 do begin
x := 0 + 10 * i / (N - 1);
y := Cos(x) + x;
chFitLineSeries1.AddXY(x, y + (Random - 1) * NOISE);
end;
chFitFitSeries1.Source := chFitLineSeries1.Source;
end;
procedure TForm1.rgDataPointModeClick(Sender: TObject);
begin
with ctDistance1 do begin
@ -225,6 +300,11 @@ begin
UpdateButtons;
end;
procedure TForm1.rgFitParamCountClick(Sender: TObject);
begin
chFitFitSeries1.ParamCount := rgFitParamCount.ItemIndex + 1;
end;
procedure TForm1.rgMeasureModeClick(Sender: TObject);
begin
ctDistance1.MeasureMode := TChartDistanceMode(rgMeasureMode.ItemIndex);