Function with time issue

TeeChart VCL for Borland/CodeGear/Embarcadero RAD Studio, Delphi and C++ Builder.
Post Reply
GoToXY
Newbie
Newbie
Posts: 81
Joined: Thu Apr 03, 2008 12:00 am

Function with time issue

Post by GoToXY » Thu Jun 17, 2010 12:23 pm

Hi everyone.

I got a new issue and i would like to know if i'm getting this issue because i dont use teechart the right way i should. I found a really big issue with the function when i use a datetime for the X axis using psRange. It doesn't seems to calculate it correctly because i have 2 different chart (teeChart and Excel) and when i do check it manually, TeeChart doesnt do it right. When using add function, If i have some series with less data than the others, the fun begins. It seems it doesn nearly the same thing as if it were set to psNumPoint because it doesnt seem to care about my datetime but only the number of points.

I did add a screenshot that show how it goes. The teal series is the total (add function) and you can see easely that the slope doesnt follow the time line of the other series.
ss-add-issue.jpg
ScreenShot
ss-add-issue.jpg (489.08 KiB) Viewed 11927 times
I hope there is a simple answer to that because otherwise, i will have to do an other add function that work well with a datetime base.

* i forgot to tell you some stuff:
Series.SetFunction(TAddTeeFunction.Create(Chart))
Series.FunctionType.PeriodStyle := psRange
Series.FunctionType.Period := DateTimeStep[dtOneMinute];
Series.DataSources.Clear;
Looping for Series.DataSources.Add(SeriestoBeAdded)
Series.CheckDataSource;

D2010, TeeChart v8.06

Yeray
Site Admin
Site Admin
Posts: 9602
Joined: Tue Dec 05, 2006 12:00 am
Location: Girona, Catalonia
Contact:

Re: Function with time issue

Post by Yeray » Fri Jun 18, 2010 11:03 am

Hi GoToXY,

I can't reproduce the problem with the following code:

Code: Select all

uses series, TeeFunci;

procedure TForm1.FormCreate(Sender: TObject);
var i, j: Integer;
    tmpdate: TDateTime;
begin
  Chart1.View3D:=false;

  for i:=0 to 1 do
  with Chart1.AddSeries(TFastLineSeries) do
  begin
    XValues.DateTime:=true;
    tmpdate:=Date;

    for j:=0 to 20 do
    begin
      if ((i = 0) and (j mod 10 > 5)) then
        AddXY(tmpdate + j, 10)
      else
        AddXY(tmpdate + j, 20);
    end;
  end;

  with Chart1.AddSeries(TFastLineSeries) do
  begin
    SetFunction(TAddTeeFunction.Create(self));
    FunctionType.PeriodStyle:=psRange;
    FunctionType.Period:=DateTimeStep[dtOneMinute];
    DataSources.Add(Chart1[0]);
    DataSources.Add(Chart1[1]);
  end;
end;
Do you see any important step that I could miss trying to reproduce the problem?
Please, modify the code above so we can run it as-is to reproduce the problem here (or send us a simple example project)
Best Regards,
ImageYeray Alonso
Development & Support
Steema Software
Av. Montilivi 33, 17003 Girona, Catalonia (SP)
Image Image Image Image Image Image Please read our Bug Fixing Policy

GoToXY
Newbie
Newbie
Posts: 81
Joined: Thu Apr 03, 2008 12:00 am

Re: Function with time issue

Post by GoToXY » Fri Jun 18, 2010 12:14 pm

Hi YEray,

First i think you need more data than what you use otherwise it is hard to see the error.

You used days not minute in your example. adding 1 to a date will add a day, we have to work on minutes to see it (maybe we can see it too in days, be as we are using dtOneMinute, it would appear to be more realistic to use minute)

I will try to make a simple application to show you what i mean.

GoToXY
Newbie
Newbie
Posts: 81
Joined: Thu Apr 03, 2008 12:00 am

Re: Function with time issue

Post by GoToXY » Fri Jun 18, 2010 12:49 pm

Ok, i found a way to show you the error and im pretty sure you gonna be very surprise with the result.

Here a Screenshot of the sample application
ss-add-issue2.jpg
screenshot
ss-add-issue2.jpg (124.87 KiB) Viewed 11843 times
As you can see, logically, add those lines would result in a straight Line with no stairs starting from 500. but what we are getting is how it add stuff in the wrong way.

I think we will have this issue with all the function so far, because it seems to be a DateTime baseline issue.
Attachments
AddFunction.zip
Sample application test
(7.9 KiB) Downloaded 486 times

Yeray
Site Admin
Site Admin
Posts: 9602
Joined: Tue Dec 05, 2006 12:00 am
Location: Girona, Catalonia
Contact:

Re: Function with time issue

Post by Yeray » Mon Jun 21, 2010 9:16 am

Hi GoToXY,

You are right. I think that the functions don't support sources with different increments in X. I've added it to the defect list to be fixed in future releases (TV52014986).
Thanks for reporting it.
Best Regards,
ImageYeray Alonso
Development & Support
Steema Software
Av. Montilivi 33, 17003 Girona, Catalonia (SP)
Image Image Image Image Image Image Please read our Bug Fixing Policy

GoToXY
Newbie
Newbie
Posts: 81
Joined: Thu Apr 03, 2008 12:00 am

Re: Function with time issue

Post by GoToXY » Tue Jun 22, 2010 7:15 pm

Yeray wrote:Hi GoToXY,

You are right. I think that the functions don't support sources with different increments in X. I've added it to the defect list to be fixed in future releases (TV52014986).
Thanks for reporting it.
Any date on the next update because that kind of error really put us in a bad position toward our customer.I can't use any of the function in TChart because of that issue and to be honest with you, without that, TChart is becoming very useless for us.

Thanks again Yeray

Yeray
Site Admin
Site Admin
Posts: 9602
Joined: Tue Dec 05, 2006 12:00 am
Location: Girona, Catalonia
Contact:

Re: Function with time issue

Post by Yeray » Wed Jun 23, 2010 11:48 am

Hi GoToXY,

Investigating this a little bit more, we've seen that this would be the expected result, similar to the discussed here and here.

The problem is that these calculations need their sources to have the same number of X values so they can be done correclty.
Here you have an example similar to yours and the workaround that consists on adding null points where a series hasn't a value but the other has:

Code: Select all

uses Series, TeeFunci, Math;

procedure TForm1.FormCreate(Sender: TObject);
Var i: Integer;
begin
  Chart1.View3D:=false;

  For i := 0 To 2 Do
  begin
    Chart1.AddSeries(TLineSeries);
    (Chart1[i] as TLineSeries).Pointer.Visible:=true;
  end;

  Chart1[2].Color := clRed;
  Chart1[2].SetFunction(TAddTeeFunction.Create(Chart1));

  For i := 0 To 1 Do
    Chart1[2].DataSources.Add(Chart1[i]);

  CheckBox1Click(self);
end;

procedure TForm1.CheckBox1Click(Sender: TObject);
Var i,j,MaxCount: Integer;
begin
  For i:=0 To 1 Do
    Chart1[i].Clear;

  if CheckBox1.Checked then
  begin
    Chart1[0].AddXY(0,5);
    Chart1[0].AddXY(2,5);
    Chart1[0].AddXY(1,5);

    Chart1[1].AddXY(0,10);
    Chart1[1].AddXY(5,10);
    Chart1[1].AddXY(10,10);

    //workaround
    i:=0;
    while i < Max(Chart1[0].Count, Chart1[1].Count) do
    begin
      if ((i >= Chart1[0].Count) or (Chart1[0].XValue[i] > Chart1[1].XValue[i])) then
        Chart1[0].AddNullXY(Chart1[1].XValue[i],0)
      else
        if ((i >= Chart1[1].Count) or (Chart1[0].XValue[i] < Chart1[1].XValue[i])) then
          Chart1[1].AddNullXY(Chart1[0].XValue[i],0);
      i:=i+1;
    end;

    Chart1[0].XValues.Order:=loAscending;
    Chart1[1].XValues.Order:=loAscending;
    (Chart1[0] as TLineSeries).TreatNulls:=tnSkip;
    (Chart1[1] as TLineSeries).TreatNulls:=tnSkip;
    //end workaround
  end
  else
  begin
    Chart1[0].Add(5);
    Chart1[0].Add(5);
    Chart1[0].Add(5);
    Chart1[1].Add(10);
    Chart1[1].Add(10);
    Chart1[1].Add(10);
  end;

  Chart1[2].CheckDataSource;
end;
Best Regards,
ImageYeray Alonso
Development & Support
Steema Software
Av. Montilivi 33, 17003 Girona, Catalonia (SP)
Image Image Image Image Image Image Please read our Bug Fixing Policy

GoToXY
Newbie
Newbie
Posts: 81
Joined: Thu Apr 03, 2008 12:00 am

Re: Function with time issue

Post by GoToXY » Thu Aug 26, 2010 6:53 pm

Sorry, i havent seen you had reply on this one. I did try the "workAround" but no, it doesnt work at all. i got lots of points that goes to 1899-12-30 (wierd because the AddNullXY(TheDate,0)

with the copy of the workaround
addfncbug1.jpg
addfncbug1.jpg (120.06 KiB) Viewed 11785 times
Attachments
addfncbug2.jpg
addfncbug2.jpg (92.31 KiB) Viewed 11754 times

GoToXY
Newbie
Newbie
Posts: 81
Joined: Thu Apr 03, 2008 12:00 am

Re: Function with time issue

Post by GoToXY » Thu Aug 26, 2010 7:24 pm

Ok, i did managed to solve the null date by doing

Code: Select all

while i < Max(Chart1[0].Count, Chart1[1].Count)-1 do
This is what i got
addfncbug3.jpg
addfncbug3.jpg (182.9 KiB) Viewed 11743 times
As you can see, It is very a theorical workaround and not a practical one. I did others test and the best i could get so far is this
addfncbug4.jpg
addfncbug4.jpg (123.24 KiB) Viewed 11747 times

To get that line i had to change the workaround by changing the Y= value 0 in the addNullXY to the nearest old value of the adding series

Code: Select all

   //workaround
    i:=0;
    while i < Max(Chart1[0].Count, Chart1[1].Count)-1 do
    begin
      if ((i >= Chart1[0].Count) or (Chart1[0].XValue[i] > Chart1[1].XValue[i])) then
        Chart1[0].AddNullXY(Chart1[1].XValue[i],Chart1[0].YValues[i-1])
      else
        if ((i >= Chart1[1].Count) or (Chart1[0].XValue[i] < Chart1[1].XValue[i])) then
          Chart1[1].AddNullXY(Chart1[0].XValue[i],Chart1[1].YValues[i-1]);
      i:=i+1;
    end;

    Chart1[0].XValues.Order:=loAscending;
    Chart1[1].XValues.Order:=loAscending;
    (Chart1[0] as TLineSeries).TreatNulls:=tnSkip;
    (Chart1[1] as TLineSeries).TreatNulls:=tnSkip;
    //end workaround
If you come across a beter idea, please let me know.

Yeray
Site Admin
Site Admin
Posts: 9602
Joined: Tue Dec 05, 2006 12:00 am
Location: Girona, Catalonia
Contact:

Re: Function with time issue

Post by Yeray » Fri Aug 27, 2010 4:09 pm

Hi GoToXY,

That's right, if you want your function to consider the "missing points" to have the value on the line, another option could be calculating the interpolation point instead of using the last YValue.
Take a look at the demo at All features\Welcome!\Chart Styles\Standard\Line (Strip)\Interpolating Line series
Best Regards,
ImageYeray Alonso
Development & Support
Steema Software
Av. Montilivi 33, 17003 Girona, Catalonia (SP)
Image Image Image Image Image Image Please read our Bug Fixing Policy

GoToXY
Newbie
Newbie
Posts: 81
Joined: Thu Apr 03, 2008 12:00 am

Re: Function with time issue

Post by GoToXY » Fri Aug 27, 2010 5:21 pm

Yes, i did it 1 hour ago, just havent got the time to paste my code here tho. Oh i didnt know you guys already had done those thing in the demo. Anyway, everything is working fine now.

Thanks again for your support!

Post Reply