📄 chart.pas
字号:
TChartAxisAccess(Axis).IHideSideGrid:=True;
TChartAxisAccess(Axis).DrawGrids(Length(Axis.Tick));
TChartAxisAccess(Axis).IHideSideGrid:=False;
end;
end;
Procedure DrawTitleFoot(CustomOnly:Boolean);
Procedure DoDrawTitle(ATitle:TChartTitle);
begin
if ATitle.CustomPosition=CustomOnly then ATitle.DrawTitle; { 5.02 }
end;
Begin
DoDrawTitle(FTitle);
DoDrawTitle(FSubTitle);
DoDrawTitle(FFoot);
DoDrawTitle(FSubFoot);
end;
{ draw title and foot, or draw foot and title, depending
if legend is at left/right or at top/bottom. }
{ top/bottom legends need to leave space for the title and foot
before they get displayed. }
{ If the Legend.CustomPosition is True, then draw the Legend AFTER
all Series and Axes (on top of chart) }
begin
Canvas.FrontPlaneBegin;
if BeforeSeries then
begin { draw titles and legend before series }
if (not Legend.CustomPosition) and Legend.ShouldDraw then
begin
if Legend.Vertical then
begin
Legend.DrawLegend;
DrawTitleFoot(False);
end
else
begin
DrawTitleFoot(False);
Legend.DrawLegend;
end;
end
else DrawTitleFoot(False);
end
else
begin { after series }
if Legend.CustomPosition and Legend.ShouldDraw then
Legend.DrawLegend;
DrawTitleFoot(True);
end;
Canvas.FrontPlaneEnd;
if not BeforeSeries then
if ActiveSeriesUseAxis then
begin
if View3D then
begin
if DrawRightWallAfter then
begin
if Walls.Right.ShouldDraw then
DrawRightWall;
DrawAxisAfter(RightAxis);
end;
if DrawLeftWallFirst then
begin
if Walls.Left.ShouldDraw then
DrawLeftWall;
DrawAxisAfter(LeftAxis);
end;
if DrawBackWallAfter(Width3D) then
begin
DrawAxisGridAfter(TopAxis);
DrawAxisGridAfter(BottomAxis);
if Walls.Back.ShouldDraw then
DrawBackWall;
end;
end;
end;
end;
// Returns wall size in pixels corresponding to Axis parameter.
// For example: Left axis corresponds to Left wall.
Function TCustomChart.CalcWallSize(Axis:TChartAxis):Integer;
var tmpW : TCustomChartWall;
begin
result:=0;
if View3D and View3DWalls then
begin
if Axis=LeftAxis then tmpW:=Walls.Left else
if Axis=BottomAxis then tmpW:=Walls.Bottom else
if Axis=RightAxis then tmpW:=Walls.Right else tmpW:=Walls.Back;
if tmpW.Visible then result:=tmpW.Size;
end;
end;
Function TCustomChart.ActiveSeriesUseAxis:Boolean;
var t : Integer;
begin
result:=True;
for t:=0 to SeriesCount-1 do
With Series[t] do
if Active then
if UseAxis then
begin
result:=True;
Exit;
end
else result:=False;
end;
Procedure TCustomChart.PrepareWallCanvas(AWall:TChartWall);
begin
With AWall do
begin
Canvas.AssignVisiblePen(Frame);
if Transparent then Canvas.Brush.Style:=bsClear
else SetBrushCanvas(Color,Brush,Brush.Color)
end;
end;
Procedure TCustomChart.DrawLeftWall; { Left wall only }
var tmpB : Integer;
tmpBlend : TTeeBlend;
begin
if View3D and View3DWalls then
begin
PrepareWallCanvas(LeftWall);
tmpB:=ChartRect.Bottom+CalcWallSize(BottomAxis);
tmpBlend:=LeftWall.TryDrawWall(ChartRect.Left,tmpB);
With LeftWall,ChartRect do
if Size>0 then
Canvas.Cube(Left-Size,Left,Top,tmpB,0,Width3D,ApplyDark3D)
else
Canvas.RectangleZ(Left,Top,tmpB,0,Width3D);
if (not LeftWall.Transparent) and (LeftWall.Transparency>0) then
Canvas.EndBlending(tmpBlend);
end;
end;
type
TCanvasAccess=class(TCanvas3D);
Procedure TCustomChart.DrawBackWall;
var tmpRect : TRect;
Procedure DrawBackWallGradient;
var P : TFourPoints;
begin
if (not BackWall.Transparent) and BackWall.HasGradient then
begin
if View3DOptions.Orthogonal then
BackWall.Gradient.Draw(Canvas,Canvas.CalcRect3D(tmpRect,Width3D))
else
begin
if Canvas.SupportsFullRotation then
begin
TCanvasAccess(Canvas).GradientZ:=Width3D;
BackWall.Gradient.Draw(Canvas,tmpRect);
TCanvasAccess(Canvas).GradientZ:=0;
end
else
begin
P:=Canvas.FourPointsFromRect(tmpRect,Width3D);
BackWall.Gradient.Draw(Canvas,P);
end;
end;
if not Canvas.SupportsFullRotation then
Canvas.Brush.Style:=bsClear;
end;
end;
var tmpBlend : TTeeBlend;
Procedure CreateBlender;
begin
with BackWall do
if Transparency>0 then
tmpBlend:=Canvas.BeginBlending(Canvas.RectFromRectZ(tmpRect,Width3D),Transparency);
end;
var tmp : Integer;
tmpSize : Integer;
begin
With BackWall do
begin
PrepareWallCanvas(BackWall);
if View3D then
begin
if View3DWalls then
begin
if Width3D<0 then tmp:=-Size else tmp:=Size;
if Size>0 then
begin
tmpSize:=CalcWallSize(LeftAxis);
with ChartRect do
tmpRect:=TeeRect( Left-tmpSize,Top,
Right,Bottom+CalcWallSize(BottomAxis))
end
else
tmpRect:=ChartRect;
CreateBlender;
DrawBackWallGradient;
if Size>0 then
Canvas.Cube(tmpRect,Width3D,Width3D+tmp,ApplyDark3D)
else
Canvas.RectangleWithZ(tmpRect,Width3D);
end;
end
else
begin
With ChartRect do
tmpRect:=TeeRect(Left,Top,Succ(Right),Succ(Bottom));
CreateBlender;
if Gradient.Visible and (not Transparent) then
begin
Gradient.Draw(Canvas,tmpRect);
Canvas.Brush.Style:=bsClear;
end;
Canvas.Rectangle(tmpRect);
end;
if HasBackImage and BackImage.Inside then
begin
tmpRect:=ChartRect;
if Pen.Visible then
begin
Inc(tmpRect.Top);
Inc(tmpRect.Left);
end;
DrawBitmap(tmpRect,Width3D);
end;
if Transparency>0 then Canvas.EndBlending(tmpBlend);
end;
end;
Procedure TCustomChart.DrawWalls; { Left and Bottom wall only }
Procedure DrawBottomWall;
var P : TFourPoints;
tmpB : Integer;
tmpLeft : Integer;
Procedure CalcBottomWallPoints;
begin
tmpB:=ChartRect.Bottom;
P[0]:=Canvas.Calculate3DPosition(tmpLeft, tmpB,0);
P[1]:=Canvas.Calculate3DPosition(tmpLeft, tmpB,Width3D);
P[2]:=Canvas.Calculate3DPosition(ChartRect.Right, tmpB,Width3D);
P[3]:=Canvas.Calculate3DPosition(ChartRect.Right, tmpB,0);
end;
var tmpBlend : TTeeBlend;
tmpRight : Integer;
begin
PrepareWallCanvas(BottomWall);
tmpB:=ChartRect.Bottom;
if Canvas.SupportsFullRotation then Inc(tmpB);
tmpLeft:=ChartRect.Left;
with Walls.Left do
if Visible and ((not AutoHide) or DrawLeftWallFirst) then // 7.0
Dec(tmpLeft,CalcWallSize(Axes.Left));
tmpBlend:=nil;
if not BottomWall.Transparent then
begin
CalcBottomWallPoints;
if BottomWall.Transparency>0 then // 5.03
tmpBlend:=Canvas.BeginBlending(RectFromPolygon(P,4),BottomWall.Transparency);
if BottomWall.HasGradient then
begin
BottomWall.Gradient.Draw(Canvas,P);
Canvas.Brush.Style:=bsClear;
end;
end;
tmpRight:=ChartRect.Right;
With BottomWall do
begin
if Size>0 then
Canvas.Cube(tmpLeft,tmpRight,tmpB,tmpB+Size,0,Width3D,ApplyDark3D)
else
Canvas.RectangleY(tmpLeft,tmpB,tmpRight,0,Width3D);
end;
if (not BottomWall.Transparent) and
(BottomWall.Transparency>0) then Canvas.EndBlending(tmpBlend);
end;
begin
if ActiveSeriesUseAxis then
begin
if View3D and View3DWalls then
begin
if (RightWall.Visible) and (not DrawRightWallAfter) then
DrawRightWall;
end;
if View3DWalls then
if BackWall.Visible and (not DrawBackWallAfter(Width3D)) then
DrawBackWall;
if View3D and View3DWalls then
begin
if LeftWall.Visible and (not DrawLeftWallFirst) then
DrawLeftWall;
if BottomWall.Visible then DrawBottomWall;
if DrawBackWallAfter(0) then
begin
if IsAxisVisible(Axes.Top) then Axes.Top.Draw(True);
if IsAxisVisible(Axes.Bottom) then Axes.Bottom.Draw(True);
end;
end;
end;
end;
Procedure TCustomChart.SeriesUp(ASeries:TChartSeries);
var t : Integer;
Begin { scroll up ASeries in SeriesList. This changes the Z order }
t:=SeriesList.IndexOf(ASeries);
if t>0 then ExchangeSeries(t,t-1);
end;
Procedure TCustomChart.SeriesDown(ASeries:TChartSeries);
var t : Integer;
Begin { scroll down ASeries in SeriesList. This changes the Z order }
t:=SeriesList.IndexOf(ASeries);
if t<SeriesCount-1 then ExchangeSeries(t,t+1);
end;
Procedure TCustomChart.NextPage;
Begin
if (MaxPointsPerPage>0) and (Page<NumPages) then Page:=Page+1;
End;
Procedure TCustomChart.PreviousPage;
Begin
if (MaxPointsPerPage>0) and (Page>1) then Page:=Page-1;
End;
Procedure TCustomChart.RemoveAllSeries;
Begin
While SeriesCount>0 do RemoveSeries(Series[0]);
End;
Procedure TCustomChart.DoZoom(Const topi,topf,boti,botf,lefi,leff,rigi,rigf:Double);
Procedure DoZoomAnimated;
Procedure ZoomAxis(AAxis:TChartAxis; Const tmpA,tmpB:Double);
Begin { apply a portion of the desired zoom to achieve animation }
with AAxis do
SetMinMax(Minimum+((tmpA-Minimum)/AnimatedZoomFactor),
Maximum-((Maximum-tmpB)/AnimatedZoomFactor));
end;
Var t : Integer;
begin
for t:=1 to Zoom.AnimatedSteps-1 do
begin
ZoomAxis(LeftAxis,Lefi,Leff);
ZoomAxis(RightAxis,Rigi,Rigf);
ZoomAxis(TopAxis,Topi,Topf);
ZoomAxis(BottomAxis,Boti,Botf);
Refresh; // force repaint
// OnAnimatedZoom event ?
end;
end;
Begin
if RestoredAxisScales then
begin
FSavedScales:=SaveScales;
RestoredAxisScales:=False;
end;
if Zoom.Animated then DoZoomAnimated; { animation... }
{ final zoom }
LeftAxis.SetMinMax(Lefi,Leff);
RightAxis.SetMinMax(Rigi,Rigf);
TopAxis.SetMinMax(Topi,Topf);
BottomAxis.SetMinMax(Boti,Botf);
Zoomed:=True;
if Assigned(FOnZoom) then FOnZoom(Self);
end;
Procedure TCustomChart.ZoomRect(Const Rect:TRect);
Begin
With Zoom do
Begin
X0:=Rect.Left;
Y0:=Rect.Top;
X1:=Rect.Right;
Y1:=Rect.Bottom;
CalcZoomPoints;
end;
End;
Procedure TCustomChart.ZoomPercent(Const PercentZoom:Double);
Procedure CalcAxisScale(Axis:TChartAxis; Var tmpA,tmpB:Double);
Var tmpDelta : Double;
AMin : Double;
AMax : Double;
Begin
AMin:=Axis.Minimum;
AMax:=Axis.Maximum;
Axis.CalcMinMax(AMin,AMax);
tmpDelta:=(AMax-AMin)*(PercentZoom-100.0)*0.01;
tmpA:=AMin+tmpDelta;
tmpB:=AMax-tmpDelta;
end;
var Lefi : Double;
Leff : Double;
Rigi : Double;
Rigf : Double;
Topi : Double;
Topf : Double;
Boti : Double;
Botf : Double;
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -