TAChart: Modify candlestick plot to allow for same color of body and tails

git-svn-id: trunk@46442 -
This commit is contained in:
wp 2014-10-06 15:37:22 +00:00
parent 55ab14b399
commit 7c57e7d617
3 changed files with 136 additions and 40 deletions

View File

@ -1,51 +1,16 @@
object MainForm: TMainForm
Left = 313
Height = 438
Height = 466
Top = 177
Width = 891
Caption = 'MainForm'
ClientHeight = 438
ClientHeight = 466
ClientWidth = 891
OnCreate = FormCreate
LCLVersion = '1.3'
object TopPanel: TPanel
Left = 0
Height = 42
Top = 0
Width = 891
Align = alTop
BevelOuter = bvNone
ClientHeight = 42
ClientWidth = 891
TabOrder = 0
object cbSeriesType: TComboBox
Left = 8
Height = 23
Top = 8
Width = 242
ItemHeight = 15
ItemIndex = 0
Items.Strings = (
'OHLC series'
'Candle stick series'
)
OnChange = cbSeriesTypeChange
Style = csDropDownList
TabOrder = 0
Text = 'OHLC series'
end
object Label1: TLabel
Left = 266
Height = 15
Top = 12
Width = 523
Caption = 'Hold the left mouse button down to see a hint window with the stock prices above each data point.'
ParentColor = False
end
end
object FinancialChart: TChart
Left = 0
Height = 396
Height = 382
Top = 42
Width = 891
AxisList = <
@ -83,6 +48,7 @@ object MainForm: TMainForm
ParentColor = False
object ohlcSeries: TOpenHighLowCloseSeries
CandlestickDownBrush.Color = clRed
CandlestickLinePen.Color = clDefault
CandlestickUpBrush.Color = clLime
DownLinePen.Color = clRed
DownLinePen.Width = 2
@ -91,6 +57,95 @@ object MainForm: TMainForm
Mode = mOHLC
end
end
object BottomPanel: TPanel
Left = 0
Height = 42
Top = 424
Width = 891
Align = alBottom
BevelOuter = bvNone
Caption = 'Hold the left mouse button down to see a hint window with the stock prices above each data point.'
TabOrder = 1
end
object TopPanel: TPanel
Left = 0
Height = 42
Top = 0
Width = 891
Align = alTop
BevelOuter = bvNone
ClientHeight = 42
ClientWidth = 891
TabOrder = 2
object cbSeriesType: TComboBox
Left = 8
Height = 28
Top = 8
Width = 242
ItemHeight = 20
ItemIndex = 0
Items.Strings = (
'OHLC series'
'Candle stick series'
)
OnChange = cbSeriesTypeChange
Style = csDropDownList
TabOrder = 0
Text = 'OHLC series'
end
object cbCandleStickSameColor: TCheckBox
Left = 600
Height = 24
Top = 10
Width = 218
Caption = 'same color for tails and body'
Checked = True
OnChange = cbCandleStickSameColorChange
State = cbChecked
TabOrder = 1
Visible = False
end
object cbUpColor: TColorBox
Left = 296
Height = 26
Top = 10
Width = 100
Selected = clLime
Style = [cbStandardColors, cbExtendedColors, cbIncludeNone, cbIncludeDefault, cbCustomColor, cbPrettyNames, cbCustomColors]
ItemHeight = 20
OnChange = cbColorChange
TabOrder = 2
end
object cbDownColor: TColorBox
Left = 464
Height = 28
Top = 8
Width = 100
Selected = clRed
Style = [cbStandardColors, cbExtendedColors, cbIncludeNone, cbIncludeDefault, cbCustomColor, cbPrettyNames, cbCustomColors]
ItemHeight = 20
OnChange = cbColorChange
TabOrder = 3
end
object LblUp: TLabel
Left = 264
Height = 20
Top = 12
Width = 19
Caption = 'Up'
FocusControl = cbUpColor
ParentColor = False
end
object LblDown: TLabel
Left = 413
Height = 20
Top = 12
Width = 39
Caption = 'Down'
FocusControl = cbDownColor
ParentColor = False
end
end
object ChartToolset1: TChartToolset
left = 160
top = 111

View File

@ -6,21 +6,28 @@ interface
uses
Classes, SysUtils, FileUtil, TAGraph, TAMultiSeries, TATools,
Forms, Controls, Graphics, Dialogs, ExtCtrls, StdCtrls, types;
Forms, Controls, Graphics, Dialogs, ExtCtrls, StdCtrls, ColorBox, types;
type
{ TMainForm }
TMainForm = class(TForm)
cbCandleStickSameColor: TCheckBox;
cbSeriesType: TComboBox;
ChartToolset1: TChartToolset;
cbUpColor: TColorBox;
cbDownColor: TColorBox;
DataPointHintTool: TDataPointHintTool;
FinancialChart: TChart;
Label1: TLabel;
LblDown: TLabel;
LblUp: TLabel;
ohlcSeries: TOpenHighLowCloseSeries;
BottomPanel: TPanel;
TopPanel: TPanel;
procedure cbCandleStickSameColorChange(Sender: TObject);
procedure cbSeriesTypeChange(Sender: TObject);
procedure cbColorChange(Sender: TObject);
procedure DataPointHintToolHint(ATool: TDataPointHintTool;
const APoint: TPoint; var AHint: String);
procedure DataPointHintToolHintLocation(ATool: TDataPointHintTool;
@ -91,6 +98,31 @@ end;
procedure TMainForm.cbSeriesTypeChange(Sender: TObject);
begin
ohlcSeries.Mode := TOHLCMode(CbSeriesType.ItemIndex);
cbCandleStickSameColor.Visible := cbSeriesType.ItemIndex = 1;
end;
procedure TMainForm.cbColorChange(Sender: TObject);
begin
case ohlcSeries.Mode of
mOHLC:
begin
ohlcSeries.LinePen.Color := cbUpColor.Selected;
ohlcSeries.DownLinePen.Color := cbDownColor.Selected;
end;
mCandleStick:
begin
ohlcSeries.CandlestickUpBrush.Color := cbUpColor.Selected;
ohlcSeries.CandleStickDownBrush.Color := cbDownColor.Selected;
end;
end;
end;
procedure TMainForm.cbCandleStickSameColorChange(Sender: TObject);
begin
if cbCandleStickSameColor.Checked then
ohlcSeries.CandlestickLinePen.Color := clDefault
else
ohlcSeries.CandleStickLinePen.Color := clBlack;
end;
{ This event handler returns the text to be displayed as a mouse-over hint.

View File

@ -714,8 +714,17 @@ procedure TOpenHighLowCloseSeries.Draw(ADrawer: IChartDrawer);
end;
procedure DrawCandleStick(x, yopen, yhigh, ylow, yclose, tw: Double);
var
clr: TColor;
begin
ADrawer.Pen := FCandlestickLinePen;
if FCandleStickLinePen.Color = clDefault then begin
if yopen <= yclose then
clr := FCandleStickUpBrush.Color
else
clr := FCandleStickDownBrush.Color;
ADrawer.SetPenParams(FCandleStickLinePen.Style, clr);
end;
DoLine(x, yhigh, x, ylow);
DoRect(x - tw, yopen, x + tw, yclose);
end;