delphi - 以编程方式更改 TChart 大小

标签 delphi delphi-2007 teechart

我正在以编程方式创建 tChart(Delphi2007,TeeChar 7 免费版)。我想设置图表尺寸,也许还可以更改纵横比,但更改 Width 和 Height 属性没有得到有意义的结果。我也尝试更改轴 TickLength 但没有成功。我从 dfm 文件复制了 TChart 的相关属性,以免忘记任何有意义的内容。仅当我编辑 X 和 Y 的最大值和最小值时,图形的外观才会发生变化,但这还不够。

这是我的原始图表和“重新格式化”的图表,您可以看到两者的图表尺寸均为 400 x 250。是否有用于调整图表大小的特定属性?我希望轴相应地调整大小,可以吗?谢谢您的帮助

First Chart The same chart resized

以下是与 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的属性HeightWidth。虽然您的过程调用中具有相同的名称,但使用 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/

相关文章:

delphi - 更改 ListView 项目高度

Delphi - 如何释放属于 2 个(或更多)列表的对象

delphi - 将 ALT-S 发送到窗口

delphi - gethostbyaddr 太慢

mysql - 可以 select ... into outfile 而不是将其保存到文件中,而是将其保存在 blob 中

java - 如何强制 TeeChart 画廊重绘?(swing)

delphi - 鼠标缩放: marquee color

delphi - 具有回调过程的动态 DLL - Delphi

delphi - TIdHTTP - Delphi XE 下 session 已过期消息

delphi - TeeChart TLineSeries - 是否可以为每个系列绘制多条线?