以编程方式更改TChart大小

lib*_*lib 1 delphi teechart delphi-2007

我正在以编程方式创建一个tChart(Delphi2007,TeeChar 7免费版).我想设置图表尺寸并可能更改宽高比,但我没有得到有意义的结果更改宽度和高度属性.我也尝试过改变轴TickLength而没有运气.我从dfm文件中复制了TChart的相关属​​性,而不是忘记任何有意义的东西.仅当我编辑X和Y max和min值时,图形的方面才会改变,但这还不够.

这是我的原始图表和"重新格式化"图表,因为您可以看到两者的图表尺寸均为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;
Run Code Online (Sandbox Code Playgroud)

LU *_* RD 6

我认为这里存在名称冲突.您正在使用with fChart,并且性能HeightWidthfChart.但是在过程调用中会出现相同的名称,但会使用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.
Run Code Online (Sandbox Code Playgroud)

重命名过程调用中的名称,它将按预期工作.

更好的是,避免使用with关键字.请参阅:Delphi"with"关键字是一种不好的做法吗?.

  • +1.如果可以的话,我会为最后一句加上第二个upvote.:-) (2认同)