Page 1 of 1
Candle series question
Posted: Wed May 12, 2010 11:33 am
by 16556096
Can Teechart use Cylinder Candle series?
customize every cylinder color (use Gradient)
How to implement this function?
JoJo
Re: Candle series question
Posted: Thu May 13, 2010 11:11 am
by yeray
Hi JoJo,
I'm afraid that this style isn't available for TCandleSeries. Right now, you could use TBar3DSeries and draw the two vertical lines with custom drawing techniques. For example:
Code: Select all
uses TeCanvas;
const nValues=5;
var CandleDates, CandleClose, CandleHigh, CandleLow, CandleOpen: array of double;
procedure TForm1.FormCreate(Sender: TObject);
var i: Integer;
tmp: double;
StartX: TDateTime;
begin
SetLength(CandleDates, nValues);
SetLength(CandleClose, nValues);
SetLength(CandleHigh, nValues);
SetLength(CandleLow, nValues);
SetLength(CandleOpen, nValues);
Series1.XValues.DateTime:=true;
Series1.BarStyle:=bsCilinder;
Series1.Marks.Visible:=false;
Series1.Pen.Visible:=false;
StartX:=Now;
for i:=0 to nValues-1 do
begin
CandleDates[i]:=StartX-nValues+i+1;
CandleClose[i]:=random*25;
CandleHigh[i]:=random*25+25;
CandleLow[i]:=random*25+50;
CandleOpen[i]:=random*25+75;
end;
With Series1.XValues do
begin
Value:=TChartValues(CandleDates);
Count:=nValues;
Modified:=True;
end;
With Series1.YValues do
begin
Value:=TChartValues(CandleLow);
Count:=nValues;
Modified:=True;
end;
With Series1.OffsetValues do
begin
Value:=TChartValues(CandleHigh);
Count:=nValues;
Modified:=True;
end;
Chart1.Axes.Left.SetMinMax(0,100);
Chart1.Chart3DPercent:=100;
Chart1.Aspect.Orthogonal:=false;
Chart1.Legend.Visible:=false;
end;
procedure TForm1.Chart1BeforeDrawSeries(Sender: TObject);
var i: Integer;
begin
for i:=0 to Chart1[0].Count-1 do
DrawLine(Chart1[0].XValue[i], CandleHigh[i], CandleClose[i]);
end;
procedure TForm1.Chart1AfterDraw(Sender: TObject);
var i: Integer;
begin
for i:=0 to Chart1[0].Count-1 do
DrawLine(Chart1[0].XValue[i], CandleLow[i], CandleOpen[i]);
end;
procedure TForm1.DrawLine(XVal, YStartVal, YEndVal: double);
var XPos, Y0Pos, Y1Pos: Integer;
tmpPoints: TPointArray;
begin
SetLength(tmpPoints,2);
XPos:=Chart1.Axes.Bottom.CalcXPosValue(XVal);
Y0Pos:=Chart1.Axes.Left.CalcYPosValue(YStartVal);
Y1Pos:=Chart1.Axes.Left.CalcYPosValue(YEndVal);
Chart1.Canvas.Pen.Color:=Chart1[0].Color;
tmpPoints[0]:=Point(XPos,Y0Pos);
tmpPoints[1]:=Point(XPos,Y1Pos);
tmpPoints:=Chart1.Canvas.Calc3DPoints(tmpPoints,(Chart1[0].EndZ - Chart1[0].StartZ) div 2);
Chart1.Canvas.Line(tmpPoints[0],tmpPoints[1]);
end;