Candle series question

TeeChart VCL for Borland/CodeGear/Embarcadero RAD Studio, Delphi and C++ Builder.
Post Reply
JOJO
Newbie
Newbie
Posts: 1
Joined: Wed May 05, 2010 12:00 am

Candle series question

Post by JOJO » Wed May 12, 2010 11:33 am

Can Teechart use Cylinder Candle series?
customize every cylinder color (use Gradient)
How to implement this function?

JoJo
Attachments
K_Bar.png
K_Bar.png (2.23 KiB) Viewed 1741 times

Yeray
Site Admin
Site Admin
Posts: 9612
Joined: Tue Dec 05, 2006 12:00 am
Location: Girona, Catalonia
Contact:

Re: Candle series question

Post by Yeray » Thu May 13, 2010 11:11 am

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;
Best Regards,
ImageYeray Alonso
Development & Support
Steema Software
Av. Montilivi 33, 17003 Girona, Catalonia (SP)
Image Image Image Image Image Image Please read our Bug Fixing Policy

Post Reply