⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 candlech.pas

📁 TeeChart7Source 控件
💻 PAS
📖 第 1 页 / 共 3 页
字号:
        { Draw 3D Candle }
        Brush.Color:=CalculateColor(ValueIndex);

        if Self.Pen.Visible then
           if yOpen=yClose then AssignVisiblePenColor(Self.Pen,CalculateColor(ValueIndex))
                           else AssignVisiblePen(Self.Pen)
           else
              Pen.Style:=psClear;  // 7.0

        Cube( tmpX-tmpLeftWidth,tmpX+tmpRightWidth,tmpTop,tmpBottom,
              StartZ,EndZ,Pointer.Dark3D);

        CheckHighLowPen;

        { Draw Candle Vertical Line from Top to High }
        if FCandleStyle=csCandleStick then
           VertLine3D(tmpX,tmpTop,yHigh,MiddleZ);
      end
      else
      begin
        { Draw Candle Vertical Line from High to Low }
        if FCandleStyle=csCandleStick then
           if View3D then
              VertLine3D(tmpX,yLow,yHigh,MiddleZ)
           else
              DoVertLine(tmpX,yLow,yHigh);

        { remember that Y coordinates are inverted }

        { prevent zero height rectangles 5.02 }
        { in previous releases, an horizontal line was displayed instead
          of the small candle rectangle }
        if yOpen=yClose then Dec(yClose);

        { draw the candle }
        Brush.Color:=CalculateColor(ValueIndex);

        if Self.Pen.Visible then
           if yOpen=yClose then AssignVisiblePenColor(Self.Pen,CalculateColor(ValueIndex))
                           else AssignVisiblePen(Self.Pen)
           else
              Pen.Style:=psClear;  // 7.0

        if View3D then
           RectangleWithZ(TeeRect(tmpX-tmpLeftWidth,yOpen,tmpX+tmpRightWidth,yClose),
                          MiddleZ)
        else
        begin
          if not Self.Pen.Visible then
             if yOpen<yClose then Dec(yOpen) else Dec(yClose);
          Rectangle(tmpX-tmpLeftWidth,yOpen,tmpX+tmpRightWidth+1,yClose);
        end;
      end;
    end
    else
    if FCandleStyle=csLine then  // Line
    begin
      P:=TeePoint(tmpX,YClose);

      tmpFirst:=FirstDisplayedIndex;

      if (ValueIndex<>tmpFirst) and (not IsNull(ValueIndex)) then
      begin
        AssignVisiblePenColor(Self.Pen,CalculateColor(ValueIndex));
        BackMode:=cbmTransparent;
        if View3D then LineWithZ(OldP,P,MiddleZ)
                  else Line(OldP,P);
      end;

      OldP:=P;
    end
    else
    begin // Draw Candle bar
      AssignVisiblePenColor(Self.Pen,CalculateColor(ValueIndex));
      BackMode:=cbmTransparent;

      // Draw Candle Vertical Line from High to Low
      if View3D then
      begin
        VertLine3D(tmpX,yLow,yHigh,MiddleZ);
        if ShowOpenTick then HorizLine3D(tmpX,tmpX-tmpLeftWidth-1,yOpen,MiddleZ);
        if ShowCloseTick then HorizLine3D(tmpX,tmpX+tmpRightWidth+1,yClose,MiddleZ);
      end
      else
      begin // 5.02
        DoVertLine(tmpX,yLow,yHigh);
        if ShowOpenTick then DoHorizLine(tmpX,tmpX-tmpLeftWidth-1,yOpen);
        if ShowCloseTick then DoHorizLine(tmpX,tmpX+tmpRightWidth+1,yClose);
      end;
    end;
  end;
end;

Procedure TCandleSeries.SetUpColor(Value:TColor);
Begin
  SetColorProperty(FUpCloseColor,Value);
end;

Procedure TCandleSeries.SetDownColor(Value:TColor);
Begin
  SetColorProperty(FDownCloseColor,Value);
end;

Procedure TCandleSeries.SetCandleWidth(Value:Integer);
Begin
  SetIntegerProperty(FCandleWidth,Value);
end;

Procedure TCandleSeries.SetCandleStyle(Value:TCandleStyle);
Begin
  if FCandleStyle<>Value then
  begin
    FCandleStyle:=Value;
    Pointer.Visible:=CandleStyle<>csLine;
    Repaint;
  end;
end;

class Function TCandleSeries.GetEditorClass:String;
Begin
  result:='TCandleEditor';  { <-- do not translate }
End;

Procedure TCandleSeries.PrepareForGallery(IsEnabled:Boolean);
Begin
  inherited;
  FillSampleValues(4);
  ColorEachPoint:=IsEnabled;

  if IsEnabled then
     UpCloseColor:=clBlue
  else
  begin
    UpCloseColor:=clSilver;
    DownCloseColor:=clDkGray;
    Pointer.Pen.Color:=clGray;
  end;

  Pointer.Pen.Width:=2;
  CandleWidth:=12;
end;

Procedure TCandleSeries.Assign(Source:TPersistent);
begin
  if Source is TCandleSeries then
  With TCandleSeries(Source) do
  begin
    Self.FCandleWidth   :=FCandleWidth;
    Self.FCandleStyle   :=FCandleStyle;
    Self.FUpCloseColor  :=FUpCloseColor;
    Self.FDownCloseColor:=FDownCloseColor;
    Self.HighLowPen     :=FHighLowPen;
    Self.FShowOpenTick  :=FShowOpenTick;
    Self.FShowCloseTick :=FShowCloseTick;
  end;
  inherited;
end;

Function TCandleSeries.GetDraw3D:Boolean;
begin
  result:=Pointer.Draw3D;
end;

procedure TCandleSeries.SetDraw3D(Value:Boolean);
begin
  Pointer.Draw3D:=Value;
end;

Function TCandleSeries.GetDark3D:Boolean;
begin
  result:=Pointer.Dark3D;
end;

procedure TCandleSeries.SetDark3D(Value:Boolean);
begin
  Pointer.Dark3D:=Value;
end;

Function TCandleSeries.GetPen:TChartPen;
begin
  result:=Pointer.Pen;
end;

procedure TCandleSeries.SetCandlePen(Value:TChartPen);
begin
  Pointer.Pen.Assign(Value);
end;

Function TCandleSeries.AddCandle( Const ADate:TDateTime;
                                  Const AOpen,AHigh,ALow,AClose:Double):Integer;
begin
  result:=AddOHLC(ADate,AOpen,AHigh,ALow,AClose);
end;

class procedure TCandleSeries.CreateSubGallery(
  AddSubChart: TChartSubGalleryProc);
begin
  inherited;
  AddSubChart(TeeMsg_CandleBar);
  AddSubChart(TeeMsg_CandleNoOpen);
  AddSubChart(TeeMsg_CandleNoClose);
  AddSubChart(TeeMsg_NoBorder);
  AddSubChart(TeeMsg_Line);
end;

class procedure TCandleSeries.SetSubGallery(ASeries: TChartSeries;
  Index: Integer);
begin
  With TCandleSeries(ASeries) do
  Case Index of
    1: CandleStyle:=csCandleBar;
    2: begin Pen.Show; CandleStyle:=csCandleBar; ShowOpenTick:=False; end;
    3: begin Pen.Show; CandleStyle:=csCandleBar; ShowCloseTick:=False; end;
    4: begin CandleStyle:=csCandleStick; Pen.Hide; end;
    5: begin CandleStyle:=csLine; end;
  else inherited;
  end;
end;

function TCandleSeries.ClickedCandle(ValueIndex:Integer; const P:TPoint):Boolean;
var tmpItem   : TCandleItem;
    tmpTop    : Integer;
    tmpBottom : Integer;
    tmpFirst  : Integer;
    tmpTo     : TPoint;
begin
  result:=False;

  CalcItem(ValueIndex,tmpItem);

  With tmpItem do
  Begin
    if (FCandleStyle=csCandleStick) or (FCandleStyle=csOpenClose) then
    begin
      if ParentChart.View3D and Pointer.Draw3D then
      begin
        tmpTop:=yClose;
        tmpBottom:=yOpen;
        if tmpTop>tmpBottom then SwapInteger(tmpTop,tmpBottom);

        if (FCandleStyle=csCandleStick) and
           (
             PointInLine(P,tmpX,tmpBottom,tmpX,yLow) or
             PointInLine(P,tmpX,tmpTop,tmpX,yHigh)
           )  then
        begin
          result:=True;
          exit;
        end;

        if PointInRect(TeeRect(tmpX-tmpLeftWidth,tmpTop,tmpX+tmpRightWidth,tmpBottom),P.X,P.Y) then
           result:=True;
      end
      else
      begin
        if (FCandleStyle=csCandleStick) and
           PointInLine(P,tmpX,yLow,tmpX,yHigh) then
        begin
          result:=True;
          exit;
        end;

        if yOpen=yClose then Dec(yClose);

        if ParentChart.View3D then
        begin
          if PointInRect(TeeRect(tmpX-tmpLeftWidth,yOpen,tmpX+tmpRightWidth,yClose),P.X,P.Y) then
             result:=True;
        end
        else
        begin
          if not Self.Pen.Visible then
             if yOpen<yClose then Dec(yOpen) else Dec(yClose);

          if PointInRect(TeeRect(tmpX-tmpLeftWidth,yOpen,tmpX+tmpRightWidth+1,yClose),P.X,P.Y) then
             result:=True;
        end;
      end;
    end
    else
    if CandleStyle=csLine then
    begin
      tmpFirst:=FirstDisplayedIndex;
      tmpTo:=TeePoint(tmpX,YClose);
      if ValueIndex<>tmpFirst then result:=PointInLine(P,OldP,tmpTo);
      OldP:=tmpTo;
    end
    else
    if PointInLine(P,tmpX,yLow,tmpX,yHigh) or
       (ShowOpenTick and PointInLine(P,tmpX,yOpen,tmpX-tmpLeftWidth-1,yOpen)) or
       (ShowCloseTick and PointInLine(P,tmpX,yClose,tmpX+tmpRightWidth+1,yClose)) then
       result:=True;
  end;
end;

function TCandleSeries.Clicked(x, y: Integer): Integer;
var t : Integer;
    P : TPoint;
begin
  result:=TeeNoPointClicked;

  if (FirstValueIndex>-1) and (LastValueIndex>-1) then
  begin
    if Assigned(ParentChart) then
       ParentChart.Canvas.Calculate2DPosition(X,Y,StartZ);

    P:=TeePoint(x,y);

    for t:=FirstValueIndex to LastValueIndex do
        if ClickedCandle(t,P) then
        begin
          result:=t;
          break;
        end;
  end;
end;

function TCandleSeries.LegendItemColor(LegendIndex: Integer): TColor;
begin
  result:=CalculateColor(LegendIndex);
end;

function TCandleSeries.MaxYValue: Double;
begin
  if CandleStyle=csLine then result:=CloseValues.MaxValue
                        else result:=inherited MaxYValue;
end;

function TCandleSeries.MinYValue: Double;
begin
  if CandleStyle=csLine then result:=CloseValues.MinValue
                        else result:=inherited MinYValue;
end;

procedure TCandleSeries.SetHighLowPen(const Value: TChartPen);
begin
  FHighLowPen.Assign(Value);
end;

destructor TCandleSeries.Destroy;
begin
  FHighLowPen.Free;
  inherited;
end;

{ TVolumeSeries }
Constructor TVolumeSeries.Create(AOwner: TComponent);
begin
  inherited;
  DrawArea:=False;
  DrawBetweenPoints:=False;
  ClickableLine:=False;
  Pointer.Hide;
  FUseYOrigin:=False;
end;

Function TVolumeSeries.GetVolumeValues:TChartValueList;
Begin
  result:=YValues;
end;

Procedure TVolumeSeries.SetSeriesColor(AColor:TColor);
begin
  inherited;
  LinePen.Color:=AColor;
end;

Procedure TVolumeSeries.SetVolumeValues(Value:TChartValueList);
Begin
  SetYValues(Value);
end;

Procedure TVolumeSeries.PrepareCanvas(Forced:Boolean; AColor:TColor);
begin
  if Forced or (AColor<>IColor) then
  begin
    ParentChart.Canvas.AssignVisiblePenColor(LinePen,AColor);
    ParentChart.Canvas.BackMode:=cbmTransparent;
    IColor:=AColor;
  end;
end;

procedure TVolumeSeries.DrawValue(ValueIndex:Integer);

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -