我在子界面上面有个chart控件。 在主界面上面嵌套这个子界面,结果chart不显示数据了。怎么回事????我单独运行子界面chart是有数据的呀!!!

解决方案 »

  1.   

    以下是我的子界面(也就是放chart控件的界面)代码unit Unit1;
    interface
    uses
      Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
      Dialogs, Series, TeEngine, TeeFunci, TeeProcs, Chart, ExtCtrls;
    type
      TForm1 = class(TForm)
        Panel1: TPanel;
        Chart1: TChart;
        Series1: TBarSeries;
        Series6: TBarSeries;
        TeeFunction1: TAddTeeFunction;
        Series9: THorizBarSeries;
        Timer1: TTimer;
        procedure FormCreate(Sender: TObject);
        procedure Timer1Timer(Sender: TObject);
      private
        { Private declarations }
      public
        { Public declarations }
      end;
    var
      Form1: TForm1;
    implementation
    {$R *.dfm}
    Const
      LeftAixMin:Double=0;
      LeftAixMax:Double=90;
      BottAixMin:Double=0;
      BottAixMax:Double=30000;  //定义
    var
      WPL: array of integer;
      WCount: integer;
      Zao:array[8..120] of Double;
    procedure SetChartPointsCnt;
    var
      i:integer;
    begin
      Randomize;  WCount:=150+Round(Random(10));
      setlength(WPL,WCount);
      for i:=low(WPL) to high(WPL) do
      begin
        WPL[i]:=25*Trunc(Random(1200));
      end;
    end;
    //Chart描点
    procedure ChartAddPoints(Z:array of Double);
    var
      aWCQ:array of Double;
      i:integer;
    begin  setlength(aWCQ,WCount);  Randomize;  Form1.Series1.Clear;  for i:=0 to 1000 do
        Form1.Series1.AddXY(i,0,'',clLime);
      for i:=8 to 120 do
      begin
        Form1.Series1.AddXY(i*250000,Z[i],'',clLime);
      end;
      For i:=low(WPL) to High(WPL) do
      begin
        aWCQ[i]:=Random(70);
        Form1.Series1.AddXY(WPL[i],aWCQ[i],'',clLime);
      end;
    end;  
    procedure TForm1.FormCreate(Sender: TObject);
    var
      i:integer;
    begin
      Form1.Chart1.LeftAxis.Minimum := LeftAixMin;
      Form1.Chart1.LeftAxis.Maximum := LeftAixMax;
      Form1.Chart1.BottomAxis.Maximum := BottAixMax;
      Form1.Chart1.BottomAxis.Minimum := BottAixMin;
      SetChartPointsCnt;
      for i:=8 to 120 do Zao[i]:=0;
      ChartAddPoints(Zao);
      Chart1.Show;
    end;procedure TForm1.Timer1Timer(Sender: TObject);
    begin
    ChartAddPoints(Zao);
    end;end.
      

  2.   

    以下我我主界面的代码unit Unit3;
    interface
    uses
      Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
      Dialogs, ExtCtrls;
    type
      TForm3 = class(TForm)
        pnl1: TPanel;
        procedure FormCreate(Sender: TObject);
      private
        { Private declarations }
      public
        { Public declarations }
      end;
    var
      Form3: TForm3;
    implementation
    {$R *.dfm}
    uses Unit1;
    procedure TForm3.FormCreate(Sender: TObject);
    begin
      if Form1 = nil then
      begin
        Application.CreateForm(TForm1,Form1);
      end;
      Form1:=TForm1.Create(Application);
      Form1.ManualDock(pnl1,nil,alClient);
      Form1.Visible:=True;
    end;
    end.
      

  3.   


    procedure TForm3.FormCreate(Sender: TObject);
    begin
      if Form1 = nil then
      begin
        Application.CreateForm(TForm1,Form1);
      end;
      Form1:=TForm1.Create(Application);
      Form1.ManualDock(pnl1,nil,alClient);
      Form1.Visible:=True;
    end;
    上面的代码有问题,修改一下:procedure TForm3.FormCreate(Sender: TObject);
    begin
      if not Assigned(Form1) then 
      begin
         Form1:=TForm1.Create(Application);
         Form1.Parent := pnl1;
         Form1.Align := alClient;
      end;
      Form1.Show;
    end;
      

  4.   


      for i:=0 to 1000 do
        Form1.Series1.AddXY(i,0,'',clLime);
      for i:=8 to 120 do
      begin
        Form1.Series1.AddXY(i*250000,Z[i],'',clLime);
      end;
      For i:=low(WPL) to High(WPL) do
      begin
        aWCQ[i]:=Random(70);
        Form1.Series1.AddXY(WPL[i],aWCQ[i],'',clLime);
      end;
    你这样写是什么意思,没看明白。
    为了测试是否有数据,你可以把下面的屏蔽一下嘛,比如改成这样  for i:=0 to 1000 do
        Form1.Series1.AddXY(i,i,'',clLime);
      

  5.   

    我经过各种尝试后,终于把chart的数据弄好了。主要就是把主界面加载chart子界面的代码写到了主界面的onshow方法里面就行了。