Here's a little demo that creates a gnuplot script, calls gnuplot and shows the output file in a TImage component.
For testing, create a new project, add a TImage and a TButton to the form, and assign this code to the button's OnClick:
procedure TForm1.BtnPlotClick(Sender: TObject);
const
NX = 30;
NY = 30;
XMIN = -10;
XMAX = 10;
YMIN = -10;
YMAX = 10;
var
prc: TProcess;
script: TStringList;
i,j: Integer;
x,y,z,r: Double;
tmpfile: String;
pngfile: String;
begin
pngfile := ExtractFileName(ChangeFileExt(GetTempFilename('.', 'IMG'), '.png'));
prc := TProcess.Create(nil);
try
script := TStringList.Create;
try
// Prepare gnuplot to write to a png file
script.Add(Format('set terminal png size %d, %d', [Image1.Width, Image1.Height]));
script.Add(Format('set output "%s"', [pngfile]));
// Chart title
script.Add('set title "my first 3d plot"');
// Plot command
script.Add('splot "-" using 1:2:3 with points \');
// create some data; append them to script (by using 'file name' parameter "-")
DefaultFormatSettings.DecimalSeparator := '.';
for i:=0 to NX-1 do begin
x := XMIN + (XMAX - XMIN) * i / (NX - 1);
for j:=0 to NY-1 do begin
y := YMIN + (YMAX - YMIN) * j / (NY - 1);
r := sqrt(x*x + y*y);
if r = 0 then
z := 0
else
z := sin(r)/r;
script.Add(Format('%f %f %f', [x, y, z]));
end;
end;
script.Add('end'); // this closes the data section
tmpfile := GetTempFileName('.', 'TEMP');
script.SaveToFile(tmpfile);
finally
script.Free;
end;
// run gnuplot and execute the script
prc.Executable := 'd:\programme\gnuplot\bin\gnuplot.exe';
prc.Parameters.Add(tmpfile);
prc.Options := prc.Options + [poWaitOnExit];
prc.Execute;
// load image created by the script into the TImage component
Image1.Picture.LoadfromFile(pngfile);
finally
prc.Free;
DeleteFile(pngFile);
DeleteFile(tmpFile);
end;
end;
Have a look at the gnuplot docs for further refinements of the script. Note that this script does contain the data directly. If your data are in a file you can specify the filename instead of the "-" parameter of the "splot" command.