我正在以编程方式创建 tChart(Delphi2007,TeeChar 7 免费版)。我想设置图表尺寸,也许还可以更改纵横比,但更改 Width 和 Height 属性没有得到有意义的结果。我也尝试更改轴 TickLength 但没有成功。我从 dfm 文件复制了 TChart 的相关属性,以免忘记任何有意义的内容。仅当我编辑 X 和 Y 的最大值和最小值时,图形的外观才会发生变化,但这还不够。
这是我的原始图表和“重新格式化”的图表,您可以看到两者的图表尺寸均为 400 x 250。是否有用于调整图表大小的特定属性?我希望轴相应地调整大小,可以吗?谢谢您的帮助
以下是与 TChart 相关的代码:
procedure CreateChart(parentform: TForm);
//actually formatChart is a CreateChart anf fChart a member of my class
begin
fchart:= TChart.Create(parentform);
fchart.Parent:= parentform;
fchart.AxisVisible := true;
fchart.AutoSize := false;
fChart.color := clWhite;
fchart.BottomAxis.Automatic := true;
fchart.BottomAxis.AutomaticMaximum := true;
fchart.BottomAxis.AutomaticMinimum := true;
fchart.LeftAxis.Automatic := true;
fchart.LeftAxis.AutomaticMaximum := true;
fchart.LeftAxis.AutomaticMinimum := true;
fchart.view3D := false;
end
procedure formatChart(width, height, xmin, xmax, ymin, ymax: double);
//actually formatChart is a method anf fChart a member of my class
begin
with fChart do
begin
Color := clWhite;
fChart.Legend.Visible := false;
AxisVisible := true;
AllowPanning := pmNone;
color := clWhite;
Title.Visible := False;
BottomAxis.Minimum := 0; //to avoid the error maximum must be > than min
BottomAxis.Maximum := xmax;
BottomAxis.Minimum := xmin;
BottomAxis.ExactDateTime := False ;
BottomAxis.Grid.Visible := False ;
BottomAxis.Increment := 5 ;
BottomAxis.MinorTickCount := 0;
BottomAxis.MinorTickLength := 5;
BottomAxis.Ticks.Color := clBlack ;
BottomAxis.TickOnLabelsOnly := False;
DepthAxis.Visible := False;
LeftAxis.Automatic := false;
LeftAxis.AutomaticMaximum := false;
LeftAxis.AutomaticMinimum := false;
LeftAxis.Minimum := ymin;
LeftAxis.Maximum := ymax;
LeftAxis.Minimum := ymin;
LeftAxis.TickLength := 5;
Width := round(width);
Height := round(height);
View3D := False ;
end;
end;
最佳答案
我认为这里存在名称冲突。您正在将与fChart
一起使用,以及fChart
的属性Height
和Width
。虽然您的过程调用中具有相同的名称,但使用 fChart
宽度和高度:
Width := Round(width); // The fChart property Width is used on both sides.
Height := Round(height); // The fChart property Height is used on both sides.
重命名过程调用中的名称,它将按预期工作。
更好的是,避免使用 with
关键字。请参阅:Is Delphi “with” keyword a bad practice? .
关于delphi - 以编程方式更改 TChart 大小,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/11742700/