Load data points from external text file to chart

Load data points from external text file to chart

Load data points from external text file to chart

This Delphi graphic tutorial demonstrates how to load data points to chart using external text file.

DownloadDownload This Tutorials

Bookmark:

Load data points from external text file to chart

TextFile type is a file a sequence of elements of the same type. Standard I/O routines use the redefined TextFile or Text type, which represents a file containing characters organized into lines. AssignFile method Associates the name of an external file with a file variable. Reset opens an existing file. EOF tests whether the file position is at the end of a file. ReadLN reads a line of text from a file. CloseFile closes the open file.

Load data points from external text file

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 Delphi Tutorials.

Download materials for this article (Delphi - Tutorials)

Download - Load-data-points-external-file-chart.zipLoad-data-points-external-file-chart.zip
       File size: 10 KB, File type: zip
       Total downloads: 711, Upload date: February 11 - 2009

paparazzi :: May 01-2009 :: 04:27 PM

I'm glad to see that HERE everybody can download this Delphi Tutorial, and thank you for putting this up on the net 

Chris :: June 10-2009 :: 02:41 PM

Thank you for the good intro tutorial to Charts.
In my current application I am going to implement a chart for the first time.
I will use your examples as the guide.
Cheers...

Giovanni :: March 21-2011 :: 10:01 AM

Thanks for your fine tutorials. Clear, concise, effective. Congratulations !

Leave a comment