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

📄 errorbar.pas

📁 TeeChart7Source 控件
💻 PAS
📖 第 1 页 / 共 2 页
字号:
       result:=Math.Max(result,tmp);
  end;
End;

Function TCustomErrorSeries.MinYValue:Double;
Var t      : Integer;
    tmp    : Double;
    tmpErr : Double;
Begin
  if IDrawBar then result:=inherited MinYValue else result:=0;
  for t:=0 to Count-1 do
  if IDrawBar then
  Begin
    tmpErr:=FErrorValues.Value[t];
    tmp:=YValues.Value[t];
    if tmp<0 then tmp:=tmp-tmpErr else tmp:=tmp+tmpErr;
    if tmp<result then result:=tmp;
  end
  else
  begin
    tmp:=YValues.Value[t]-FErrorValues.Value[t];
    if t=0 then
       result:=tmp
    else
       result:=Math.Min(result,tmp);
  end;
End;

Function TCustomErrorSeries.GetErrorValue(Index:Integer):Double;
Begin
  result:=FErrorValues.Value[Index];
End;

Procedure TCustomErrorSeries.SetErrorValue(Index:Integer; Const Value:Double);
Begin
  FErrorValues.Value[Index]:=Value;
End;

class Function TCustomErrorSeries.GetEditorClass:String;
Begin
  result:='TErrorSeriesEditor';
end;

Procedure TCustomErrorSeries.Assign(Source:TPersistent);
begin
  if Source is TCustomErrorSeries then
  With TCustomErrorSeries(Source) do
  begin
    Self.ErrorPen        :=FErrorPen;  // 7.0 fix
    Self.FErrorStyle     :=FErrorStyle;
    Self.FErrorWidth     :=FErrorWidth;
    Self.FErrorWidthUnits:=FErrorWidthUnits;
  end;
  inherited;
end;

Procedure TCustomErrorSeries.PrepareForGallery(IsEnabled:Boolean);
Const Colors:Array[Boolean] of TColor=(clSilver,clBlue);
      ErrorColors:Array[Boolean] of TColor=(clWhite,clRed);
begin
  inherited;
  ErrorPen.Color:=ErrorColors[IsEnabled];
  SeriesColor:=Colors[IsEnabled];
end;

Procedure TCustomErrorSeries.SetSeriesColor(AColor:TColor);
begin
  inherited;
  if not IDrawBar then ErrorPen.Color:=AColor;
end;

Procedure TCustomErrorSeries.DrawLegendShape(ValueIndex:Integer; Const Rect:TRect);
begin
  With Rect do
    DrawError( (Left+Right) div 2,(Top+Bottom) div 2,
               Right-Left,((Bottom-Top) div 2)-1,False);
end;

class Function TCustomErrorSeries.SubGalleryStack:Boolean;
begin
  result:=False; { 5.01 } { Do not show stacked styles at sub-gallery }
end;

procedure TCustomErrorSeries.PrepareLegendCanvas(ValueIndex: Integer;
  var BackColor: TColor; var BrushStyle: TBrushStyle);
begin
  PrepareErrorPen(ValueIndex);
end;

{ TErrorBarSeries }
Constructor TErrorBarSeries.Create(AOwner: TComponent);
Begin
  inherited;
  IDrawBar:=True;
  FErrorStyle:=essTop;
end;

Procedure TErrorBarSeries.PrepareForGallery(IsEnabled:Boolean);
begin
  ErrorPen.Width:=2;
  inherited;
end;

{ THighLowSeries }
Constructor THighLowSeries.Create(AOwner: TComponent);
begin
  inherited;
  CalcVisiblePoints:=False;
  Pen.Color:=clTeeColor;
  FLow:=TChartValueList.Create(Self,TeeMsg_ValuesLow);
  FHighPen:=CreateChartPen;
  FLowPen:=CreateChartPen;
  FLowBrush:=TChartBrush.Create(CanvasChanged);
  LowBrush.Style:=bsClear;
  HighBrush.Style:=bsClear;
end;

Destructor THighLowSeries.Destroy;
begin
  FHighPen.Free;
  FLowPen.Free;
  FLowBrush.Free;
  inherited;
end;

function THighLowSeries.AddHighLow(const AX, AHigh, ALow: Double;
                                   Const AXLabel:String='';
                          AColor:TColor=clTeeColor): Integer;
begin
  FLow.TempValue:=ALow;
  result:=AddXY(AX,AHigh);
end;

procedure THighLowSeries.Assign(Source: TPersistent);
begin
  if Source is THighLowSeries then
  With THighLowSeries(Source) do
  begin
    Self.HighPen :=HighPen;
    Self.LowPen  :=LowPen;
    Self.LowBrush:=LowBrush;
    Self.FTransparency:=FTransparency;
  end;
  inherited;
end;

function THighLowSeries.Clicked(x, y: Integer): Integer;
var t  : Integer;
    X0 : Integer;
    P  : TPoint;
    PS : TFourPoints;
begin
  result:=TeeNoPointClicked;

  if (FirstValueIndex<>-1) and (LastValueIndex<>-1) then  // 7.0
  begin
    P:=TeePoint(x,y);

    for t:=FirstValueIndex to LastValueIndex do
    begin
      X0:=CalcXPos(t);

      PS[2]:=ParentChart.Canvas.Calculate3DPosition(X0,CalcYPosValue(FLow.Value[t]),MiddleZ);
      PS[3]:=ParentChart.Canvas.Calculate3DPosition(X0,CalcYPos(t),MiddleZ);

      if (t<>FirstValueIndex) and PointInPolygon(P,PS) then
      begin
        result:=t;
        break;
      end;

      PS[0]:=PS[3];
      PS[1]:=PS[2];
    end;
  end;
end;

procedure THighLowSeries.DrawValue(ValueIndex: Integer);
Var X : Integer;
    View3D : Boolean;

  Procedure DrawLine(APen:TChartPen; BeginY,EndY:Integer);
  begin
    if APen.Visible then
    With ParentChart.Canvas do
    begin
      AssignVisiblePen(APen);
      if View3D then LineWithZ(OldX,BeginY,X,EndY,MiddleZ)
                else Line(OldX,BeginY,X,EndY);
    end;
  end;

  procedure DrawValueLine(AColor:TColor);
  var tmp : TColor;
  begin
    tmp:=Pen.Color;
    if tmp=clTeeColor then tmp:=AColor;

    with ParentChart.Canvas do
    begin
      AssignVisiblePenColor(Self.Pen,tmp);
      if View3D then VertLine3D(OldX,OldY0,OldY1,MiddleZ)
                else DoVertLine(OldX,OldY0,OldY1);
    end;
  end;

var Y0   : Integer;
    Y1   : Integer;
    tmpBrush : TChartBrush;
    tmpColor : TColor;
    IPoints  : TFourPoints;
    P        : TFourPoints;
    tmpBlend : TTeeBlend;
    tmpFirst : Integer;
begin
  // calculate coordinates
  x:=CalcXPos(ValueIndex);
  y0:=CalcYPos(ValueIndex);
  y1:=CalcYPosValue(FLow.Value[ValueIndex]);

  tmpFirst:=FirstDisplayedIndex;
  if ValueIndex<>tmpFirst then
  begin
    tmpColor:=ValueColor[ValueIndex-1];
    View3D:=ParentChart.View3D;

    if (not IsNull(ValueIndex)) and (not IsNull(ValueIndex-1)) then // 7.0
    begin

      // Determine brush to use (high or low)
      if LowValues.Value[ValueIndex]<HighValues.Value[ValueIndex] then
         tmpBrush:=HighBrush
      else
         tmpBrush:=LowBrush;

      // set brush
      if tmpBrush.Style<>bsClear then
      begin
        P[0].X:=OldX;
        P[0].Y:=OldY0;
        P[1].X:=OldX;
        P[1].Y:=OldY1;
        P[2].X:=X;
        P[2].Y:=Y1;
        P[3].X:=X;
        P[3].Y:=Y0;

        with ParentChart.Canvas do
        begin
          if Transparency>0 then
          begin
            IPoints[0]:=Calculate3DPosition(P[0],MiddleZ);
            IPoints[1]:=Calculate3DPosition(P[1],MiddleZ);
            IPoints[2]:=Calculate3DPosition(P[2],MiddleZ);
            IPoints[3]:=Calculate3DPosition(P[3],MiddleZ);

            tmpBlend:=BeginBlending(RectFromPolygon(IPoints,4),Transparency);
          end
          else tmpBlend:=nil;

          AssignBrush(tmpBrush,tmpColor);
          Pen.Style:=psClear;  // no pen to draw polygon

          // draw plane
          if View3D then PlaneWithZ(P,MiddleZ)
                    else Polygon(P);

          if Transparency>0 then EndBlending(tmpBlend);
        end;
      end;

      // draw lines
      DrawLine(HighPen,OldY0,Y0);
      DrawLine(LowPen,OldY1,Y1);
    end;

    // draw vertical lines
    if Pen.Visible and (not IsNull(ValueIndex-1)) then // 7.0
    begin
      DrawValueLine(tmpColor);

      if DrawValuesForward then tmpFirst:=LastValueIndex
                           else tmpFirst:=FirstValueIndex;
      if ValueIndex=tmpFirst then
      begin
        OldX:=X;
        OldY0:=Y0;
        OldY1:=Y1;
        DrawValueLine(ValueColor[ValueIndex]);
      end;
    end;
  end;

  OldX:=X;
  OldY0:=Y0;
  OldY1:=Y1;
end;

function THighLowSeries.GetHigh: TChartValueList;
begin
  result:=YValues;
end;

procedure THighLowSeries.SetHigh(const Value: TChartValueList);
begin
  SetChartValueList(YValues,Value);
end;

procedure THighLowSeries.SetLow(const Value: TChartValueList);
begin
  FLow.Assign(Value);
end;

Function THighLowSeries.IsValidSourceOf(Value:TChartSeries):Boolean;
begin
  result:=Value is THighLowSeries;
end;

Function THighLowSeries.MaxYValue:Double;
Begin
  result:=Math.Max(inherited MaxYValue,FLow.MaxValue);
End;

Function THighLowSeries.MinYValue:Double;
Begin
  result:=Math.Min(inherited MinYValue,FLow.MinValue);
End;

procedure THighLowSeries.SetHighPen(const Value: TChartPen);
begin
  FHighPen.Assign(Value);
end;

procedure THighLowSeries.SetLowPen(const Value: TChartPen);
begin
  FLowPen.Assign(Value);
end;

class function THighLowSeries.GetEditorClass: String;
begin
  result:='THighLowEditor';
end;

function THighLowSeries.GetHighBrush: TChartBrush;
begin
  result:=Brush;
end;

procedure THighLowSeries.SetHighBrush(const Value: TChartBrush);
begin
  Brush:=Value;
end;

procedure THighLowSeries.SetLowBrush(const Value: TChartBrush);
begin
  FLowBrush.Assign(Value);
end;

procedure THighLowSeries.AddSampleValues(NumValues: Integer; OnlyMandatory:Boolean=False);
Var t   : Integer;
    tmp : Double;
    s   : TSeriesRandomBounds;
Begin
  s:=RandomBounds(NumValues);
  with s do
  begin
    tmp:=RandomValue(Round(DifY));
    for t:=1 to NumValues do
    Begin
      tmp:=tmp+RandomValue(Round(DifY/5.0))-(DifY/10.0);
      AddHighLow(tmpX,{ X }
                 tmp, { High }
                 tmp-RandomValue(Round(DifY/5.0))); { Low }
      tmpX:=tmpX+StepX;
    end;
  end;
end;

class procedure THighLowSeries.CreateSubGallery(
  AddSubChart: TChartSubGalleryProc);
begin
  inherited;
  AddSubChart(TeeMsg_Filled);
  AddSubChart(TeeMsg_NoLines);
  AddSubChart(TeeMsg_NoHigh);
  AddSubChart(TeeMsg_NoLow);
end;

class procedure THighLowSeries.SetSubGallery(ASeries: TChartSeries;
  Index: Integer);
begin
  With THighLowSeries(ASeries) do
  Case Index of
    1: Brush.Style:=bsSolid;
    2: Pen.Hide;
    3: HighPen.Hide;
    4: LowPen.Hide;
  else inherited;
  end;
end;

procedure THighLowSeries.SetTransparency(const Value: TTeeTransparency);
begin
  if FTransparency<>Value then
  begin
    FTransparency:=Value;
    Repaint;
  end;
end;

initialization
  RegisterTeeSeries(TErrorBarSeries, {$IFNDEF CLR}@{$ENDIF}TeeMsg_GalleryErrorBar,
                                     {$IFNDEF CLR}@{$ENDIF}TeeMsg_GalleryStats,1);
  RegisterTeeSeries(TErrorSeries, {$IFNDEF CLR}@{$ENDIF}TeeMsg_GalleryError,
                                  {$IFNDEF CLR}@{$ENDIF}TeeMsg_GalleryStats,1);
  RegisterTeeSeries(THighLowSeries, {$IFNDEF CLR}@{$ENDIF}TeeMsg_GalleryHighLow,
                                    {$IFNDEF CLR}@{$ENDIF}TeeMsg_GalleryStats,1);
finalization
  UnRegisterTeeSeries( [TErrorBarSeries,TErrorSeries,THighLowSeries]);
end.

⌨️ 快捷键说明

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