Delphi Tutorial


Delphi Tutorial Graphic Charts - Load data points from external text file.

Delphi Tutorial Graphic Charts - Load data points from external text file.

 

Download this example

     Select following procedure in Browse button. It will show file selection dialog box and put selected file details in Edit1.Text

procedure TForm1.Button2Click(Sender: TObject);
begin
     { OpenDialog displays a file-selection dialog.
     FileName - Indicates the name and directory path of
     the last file selected. }

     If OpenDialog1.Execute Then
          Edit1.Text := OpenDialog1.FileName;
end;

 

This one reads external text data file and put the data in chart series.

procedure TForm1.Button1Click(Sender: TObject);
Var
    { A file a sequence of elements of the same type.
    Standard I/O routines use the predefined TextFile or
    Text type, which represents a file containing characters
    organized into lines. }

    Data : TextFile;

    X, Y : Real;
begin
    { This method deletes all Series values.
    Dependent Series are notified. If no new points are
    appended to the Series, nothing will be painted. }

    Chart1.Series[0].Clear;

    { Associates the name of an external file with a file variable. }
    AssignFile(Data, Edit1.Text);

    { Opens an existing file. }
    Reset(Data);

    { EOF - Tests whether the file position is at the end of a file. }
    While Not Eof(Data) Do
    Begin
        { Reads a line of text from a file. }
        Readln(Data, X, Y);

        Chart1.Series[0].AddXY(X, Y, '', clTeeColor);
    End;

    { Closes a file. }
    CloseFile(Data);
end;

DOWNLOAD this example

Click here to download this complete example for Delphi 6. (File size 9KB)

 

Go top

 


Previous Page First Page Next Page
 
Copyright © 2003 digitalcoding.com. All rights reserved.