TeeChart VCL for Borland/CodeGear/Embarcadero RAD Studio, Delphi and C++ Builder.
-
daniele_h
- Newbie
- Posts: 13
- Joined: Thu Jan 31, 2008 12:00 am
Post
by daniele_h » Tue Jul 28, 2009 8:28 am
Dear all,
I'm trying to import data from a tab-separated file to a LineSeries by code (Delphi).
Unfortunately there are many gaps (blanks/null value) so that an error occurs ("not a valid floating point value") and tha data is not imported.
I tried to use TreatNulls:=tnSkip or tnIgnore, but to no avail.
What am I donig wrong ? I'm using following code.
Code: Select all
ts := TSeriesTextSource.Create(Self);
with ts do
begin
Fields.Clear;
AddField('X',x);
AddField('Y',y);
HeaderLines := r;
FieldSeparator := dm;
DecimalSeparator := c;
FileName := fn;
ls := TLineSeries.Create(Self);
with ls do
begin
ParentChart:= ch;
DataSource := ts;
// TreatNulls := tnSkip;
ValueFormat:= la;
XValues.DateTime:= True;
ch.Axes.Bottom.DateTimeFormat := 'dd.mm.yyyy.hh:mm:ss.zzz';
ch.Axes.Bottom.LabelsAngle:= 90;
ch.Axes.Bottom.Increment:=DateTimeStep[dtOneMinute];
Title := si;
end;
Active := True;
end;
except
on E: EConvertError do
begin
Screen.Cursor := crDefault;
ls.Free;
raise Exception.Create(E.Message);
end;
end;
kind regards
Daniele
-
Yeray
- Site Admin
- Posts: 9612
- Joined: Tue Dec 05, 2006 12:00 am
- Location: Girona, Catalonia
-
Contact:
Post
by Yeray » Tue Jul 28, 2009 9:10 am
Hi Daniele,
Thanks for the code but there are many variables that we can't see their values, and we can't see the database that you are using. It would be better if you could attach here a simple example project we can run as-is to reproduce the problem here.
-
daniele_h
- Newbie
- Posts: 13
- Joined: Thu Jan 31, 2008 12:00 am
Post
by daniele_h » Tue Jul 28, 2009 9:28 am
Hi Yeray,
I was afraid you would say that it was not possible in the first place !
I'm a bit reluctant to post the whole project, but will prepare a "demo".
meanwhile, I understand your concerns about the the variables, so below find the code without variables.
I omitted to do this in the first place because I debugged enough to know it is indeed the problem of nil values. I'm not using a database dut reading from file.
Code: Select all
ts := TSeriesTextSource.Create(Self);
with ts do
begin
Fields.Clear;
AddField('X',1);
AddField('Y',1);
HeaderLines := 1;
FieldSeparator := #9;
DecimalSeparator := chr(46);
FileName := 'C:\TEMP\TabSeparated.txt';
ls := TLineSeries.Create(Self);
with ls do
begin
ParentChart:= chart1;
DataSource := ts;
// TreatNulls := tnSkip/tnIgnore; ??? <-- don't work either
ValueFormat:= '0.00e-00';
XValues.DateTime:= True;
chart1.Axes.Bottom.DateTimeFormat := 'dd.mm.yyyy.hh:mm:ss.zzz';
chart1.Axes.Bottom.LabelsAngle:= 90;
chart1.Axes.Bottom.Increment:=DateTimeStep[dtOneMinute];
Title := 'TestLine1';
end;
Active := True;
end;
except
on E: EConvertError do
begin
Screen.Cursor := crDefault;
ls.Free;
raise Exception.Create(E.Message);
end;
end;
-
daniele_h
- Newbie
- Posts: 13
- Joined: Thu Jan 31, 2008 12:00 am
Post
by daniele_h » Tue Jul 28, 2009 12:16 pm
Dear Yeray,
Please find attached a demo of the problem. (Delphi 2007, Tchart Pro v8).
In the folder you find the file "TabSeparated.txt" which is imported on "FormCreate".
You will notice the blank value (ie. 4.4). Data is imported only until the missing value.
I would expect it to continue importing with the directive "TreatNulls:=tnSkip" until the end of the file.
Kind regards
daniele
-
Attachments
-
- TChartDemo1.7z
- (6.72 KiB) Downloaded 461 times
-
Yeray
- Site Admin
- Posts: 9612
- Joined: Tue Dec 05, 2006 12:00 am
- Location: Girona, Catalonia
-
Contact:
Post
by Yeray » Tue Jul 28, 2009 3:48 pm
Hi Daniele,
Thanks for the project, now we understand better what you are trying to do.
Null values in a database must be customly handled as almost everybody marks them in a different way and also everybody wants to treat them in a different way. So you should loop through your datasource and when a null value is identified, you should manually add it to the series using the AddNull methods provided.
-
daniele_h
- Newbie
- Posts: 13
- Joined: Thu Jan 31, 2008 12:00 am
Post
by daniele_h » Tue Jul 28, 2009 4:29 pm
Hi Yeray,
I don't quite understand how I should accomplish what you are suggesting - and where/how else the "TreatNulls:=tnSkip/ignore" comes into play.
Would you be able to provide me with an example on how I should modify my code for the example I posted? I would really appreciate that.
thanks
daniele
-
Yeray
- Site Admin
- Posts: 9612
- Joined: Tue Dec 05, 2006 12:00 am
- Location: Girona, Catalonia
-
Contact:
Post
by Yeray » Wed Jul 29, 2009 8:18 am
Hi Daniele,
Change your button1 code for the following to see an example:
Code: Select all
procedure TForm1.Button1Click(Sender: TObject);
var
myFile : TextFile;
text, tmpValueText : string;
i, FieldNum : Integer;
XValue: TDateTime;
YValue: Double;
IsNull: Boolean;
begin
ls := TLineSeries.Create(Self);
with ls do
begin
ParentChart := chart1;
ValueFormat := '0.00e-00';
// TreatNulls := tnSkip; // (tnDontPaint, tnSkip, tnIgnore)
XValues.DateTime:= True;
Title := 'TestLine1';
end;
DecimalSeparator := chr(46);
DateSeparator := '.';
AssignFile(myFile, 'TabSeparated.txt');
Reset(myFile);
ReadLn(myFile, text); //we skip the first 'header' line
while not Eof(myFile) do
begin
ReadLn(myFile, text);
FieldNum := 1;
tmpValueText := '';
IsNull := false;
for i := 1 to length(text)-1 do
begin
if (text[i] = #9) then
begin
case FieldNum of
1: XValue := StrToDateTime(tmpValueText);
3: if (tmpValueText = '') then IsNull := true
else YValue := StrToFloat(tmpValueText);
end;
FieldNum := FieldNum + 1;
tmpValueText := '';
end
else tmpValueText := tmpValueText + text[i];
if (i = length(text)-1) then
begin
if IsNull then ls.AddNullXY(XValue, 0)
else ls.AddXY(XValue, YValue);
IsNull := false;
end;
end;
end;
CloseFile(myFile);
end;
-
daniele_h
- Newbie
- Posts: 13
- Joined: Thu Jan 31, 2008 12:00 am
Post
by daniele_h » Wed Jul 29, 2009 8:36 am
Dear Yeray,
You saved my day ! Works like a charm. Thank you so much
Cheers
Daniele