diff --git a/components/tachart/tacustomseries.pas b/components/tachart/tacustomseries.pas index 925d6b08f0..7b9712c24e 100644 --- a/components/tachart/tacustomseries.pas +++ b/components/tachart/tacustomseries.pas @@ -155,7 +155,7 @@ uses function TCustomChartSeries.AxisToGraph( const APoint: TDoublePoint): TDoublePoint; begin - Result := DoublePoint(AxisToGraphX(APoint.X), AxisToGraphX(APoint.Y)); + Result := DoublePoint(AxisToGraphX(APoint.X), AxisToGraphY(APoint.Y)); if IsRotated then Exchange(Result.X, Result.Y); end; diff --git a/components/tachart/tasources.pas b/components/tachart/tasources.pas index b67847359c..a2a633b0fd 100644 --- a/components/tachart/tasources.pas +++ b/components/tachart/tasources.pas @@ -309,14 +309,45 @@ end; procedure TCustomChartSource.FindBounds( AXMin, AXMax: Double; out ALB, AUB: Integer); + + function FindLB(X: Double; L, R: Integer): Integer; + begin + while L <= R do begin + Result := (R - L) div 2 + L; + if Item[Result]^.X < X then + L := Result + 1 + else + R := Result - 1; + end; + Result := L; + end; + + function FindUB(X: Double; L, R: Integer): Integer; + begin + while L <= R do begin + Result := (R - L) div 2 + L; + if Item[Result]^.X <= X then + L := Result + 1 + else + R := Result - 1; + end; + Result := R; + end; + begin EnsureOrder(AXMin, AXMax); - ALB := 0; - while (ALB < Count) and (Item[ALB]^.X < AXMin) do - Inc(ALB); - AUB := Count - 1; - while (AUB > 0) and (Item[AUB]^.X < AXMax) do - Inc(AUB); + if IsSorted then begin + ALB := FindLB(AXMin, 0, Count - 1); + AUB := FindUB(AXMax, 0, Count - 1); + end + else begin + ALB := 0; + while (ALB < Count) and (Item[ALB]^.X < AXMin) do + Inc(ALB); + AUB := Count - 1; + while (AUB > 0) and (Item[AUB]^.X < AXMax) do + Dec(AUB); + end; end; function TCustomChartSource.FormatItem(