{please compile and run following code in dephi7 teechart7}
Code: Select all
unit Unit1;
interface
uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, TeEngine, TeeTools, StdCtrls, Buttons, Series, OHLChart,
CandleCh, TeeProcs, Chart, ExtCtrls, StatChar;
type
TForm1 = class(TForm)
Panel1: TPanel;
Chart1: TChart;
Chart2: TChart;
Series1: TCandleSeries;
Series2: TBarSeries;
BitBtn1: TBitBtn;
BitBtn2: TBitBtn;
ChartTool1: TCursorTool;
ChartTool2: TCursorTool;
Chart3: TChart;
Series3: TLineSeries;
TeeFunction1: TExpMovAveFunction;
ChartTool3: TCursorTool;
procedure BitBtn1Click(Sender: TObject);
procedure ChartTool1Change(Sender: TCursorTool; x, y: Integer;
const XValue, YValue: Double; Series: TChartSeries;
ValueIndex: Integer);
procedure ChartTool2Change(Sender: TCursorTool; x, y: Integer;
const XValue, YValue: Double; Series: TChartSeries;
ValueIndex: Integer);
procedure ChartTool3Change(Sender: TCursorTool; x, y: Integer;
const XValue, YValue: Double; Series: TChartSeries;
ValueIndex: Integer);
private
{ Private declarations }
public
{ Public declarations }
end;
var
Form1: TForm1;
implementation
{$R *.dfm}
procedure CursorSynchronize(Source, Dest1,Dest2: TCursorTool);
var
i : integer;
begin
Dest1.ParentChart.AutoRepaint := False; // stop repainting
Dest1.RedrawCursor; // hide cursor
Dest2.ParentChart.AutoRepaint := False; // stop repainting
Dest2.RedrawCursor;
Dest1.XValue := Source.XValue;
Dest2.XValue := Source.XValue;
Dest2.RedrawCursor; // draw cursor again
Dest2.ParentChart.AutoRepaint := True; // enable repainting
Dest1.RedrawCursor; // draw cursor again
Dest1.ParentChart.AutoRepaint := True; // enable repainting
end;
procedure TForm1.BitBtn1Click(Sender: TObject);
begin
Series1.FillSampleValues(100);
Series2.FillSampleValues(100);
Chart1.LeftAxis.LabelsSize:=30;
Chart2.LeftAxis.LabelsSize:=30;
Chart3.LeftAxis.LabelsSize:=30;
Series2.CustomBarWidth:=Series1.CandleWidth;
end;
procedure TForm1.ChartTool1Change(Sender: TCursorTool; x, y: Integer;
const XValue, YValue: Double; Series: TChartSeries; ValueIndex: Integer);
begin
CursorSynchronize(Charttool1, Charttool2,ChartTool3);
Chart2.Repaint;
Chart3.Repaint;
end;
procedure TForm1.ChartTool2Change(Sender: TCursorTool; x, y: Integer;
const XValue, YValue: Double; Series: TChartSeries; ValueIndex: Integer);
begin
CursorSynchronize(Charttool2, Charttool1,ChartTool3);
Chart1.Repaint;
Chart3.Repaint;
end;
procedure TForm1.ChartTool3Change(Sender: TCursorTool; x, y: Integer;
const XValue, YValue: Double; Series: TChartSeries; ValueIndex: Integer);
begin
CursorSynchronize(Charttool3, Charttool1,ChartTool2);
Chart1.Repaint;
Chart2.Repaint;
end;
end.
Code: Select all
object Form1: TForm1
Left = 194
Top = 106
Width = 711
Height = 559
Caption = 'Form1'
Color = clBtnFace
Font.Charset = DEFAULT_CHARSET
Font.Color = clWindowText
Font.Height = -11
Font.Name = 'MS Sans Serif'
Font.Style = []
OldCreateOrder = False
PixelsPerInch = 96
TextHeight = 13
object Panel1: TPanel
Left = 0
Top = 0
Width = 703
Height = 481
Align = alTop
Caption = 'Panel1'
TabOrder = 0
object Chart1: TChart
Left = 1
Top = 1
Width = 701
Height = 247
MarginBottom = 0
Title.Text.Strings = (
'TChart')
BottomAxis.Inverted = True
BottomAxis.Visible = False
View3D = False
Align = alTop
TabOrder = 0
object Series1: TCandleSeries
CloseValues.Name = 'Close'
CloseValues.Order = loNone
DateValues.DateTime = False
DateValues.Name = 'Date'
DateValues.Order = loAscending
HighValues.Name = 'High'
HighValues.Order = loNone
LowValues.Name = 'Low'
LowValues.Order = loNone
OpenValues.Name = 'Open'
OpenValues.Order = loNone
Marks.Callout.Brush.Color = clBlack
Marks.Visible = False
ShowInLegend = False
HighLowPen.Color = clDefault
end
object ChartTool1: TCursorTool
FollowMouse = True
Series = Series1
Snap = True
OnChange = ChartTool1Change
end
end
object Chart2: TChart
Left = 1
Top = 349
Width = 701
Height = 131
MarginTop = 0
Title.Text.Strings = (
'TChart')
Title.Visible = False
BottomAxis.Inverted = True
TopAxis.Visible = False
View3D = False
Align = alBottom
TabOrder = 1
object Series2: TBarSeries
Marks.Callout.Brush.Color = clBlack
Marks.Visible = False
ShowInLegend = False
Gradient.Direction = gdTopBottom
XValues.Name = 'X'
XValues.Order = loAscending
YValues.Name = 'Bar'
YValues.Order = loNone
end
object ChartTool2: TCursorTool
FollowMouse = True
Series = Series2
Style = cssVertical
OnChange = ChartTool2Change
end
end
object Chart3: TChart
Left = 1
Top = 248
Width = 701
Height = 101
Legend.Visible = False
MarginBottom = 0
MarginTop = 0
Title.Text.Strings = (
'TChart')
Title.Visible = False
BottomAxis.Inverted = True
BottomAxis.Visible = False
TopAxis.Visible = False
View3D = False
Align = alClient
TabOrder = 2
object Series3: TLineSeries
Marks.Callout.Brush.Color = clBlack
Marks.Visible = False
DataSource = Series1
Pointer.InflateMargins = True
Pointer.Style = psRectangle
Pointer.Visible = False
XValues.Name = 'X'
XValues.Order = loAscending
YValues.Name = 'Y'
YValues.Order = loNone
YValues.ValueSource = 'Close'
object TeeFunction1: TExpMovAveFunction
Period = 10.000000000000000000
end
end
object ChartTool3: TCursorTool
FollowMouse = True
Series = Series3
Style = cssVertical
OnChange = ChartTool3Change
end
end
end
object BitBtn1: TBitBtn
Left = 182
Top = 496
Width = 75
Height = 25
Caption = 'Data'
TabOrder = 1
OnClick = BitBtn1Click
end
object BitBtn2: TBitBtn
Left = 284
Top = 496
Width = 75
Height = 25
Caption = 'BitBtn2'
TabOrder = 2
end
end