Bottom Axix DateTime increment

TeeChart VCL for Borland/CodeGear/Embarcadero RAD Studio, Delphi and C++ Builder.
Post Reply
Torez
Newbie
Newbie
Posts: 7
Joined: Tue May 03, 2016 12:00 am
Contact:

Bottom Axix DateTime increment

Post by Torez » Fri May 06, 2016 4:25 am

Hallo All,

My application is adding points to chart every second or twice a second.
Requirement is to have actual DateTime stamp on every point. Currently
I am struggling with Bottom Axis label. Bottom label format is :

dd/mm hh:mm:ss

and I can see this format on the chart. But when application add points every second

Code: Select all

      YValue := SomeValue;
      XValue := Series1.XValues.Last+1;
      Series1.AddXY(XValue, YValue);
increment is on Day field, not Second field. I have tried to initialize increment via

Code: Select all

Chart1.BottomAxis.Increment := DateTimeStep[dtOneSecond]
and it does not work. I can work around this problem by simply doing:

Code: Select all

      YValue := Sin(DegToRad(ValSin)) * 300 + 450;
      XValue := Series1.XValues.Last+1;
      XValuTime := FormatDateTime('dd-mm hh:nn:ss', Now );
      Series1.AddXY(XValue, YValue, YValueTime);
but problem is, once chart is saved to file and imported back, time values
are gone.

Can you please advise what to do ?

regards,

Tomas

Torez
Newbie
Newbie
Posts: 7
Joined: Tue May 03, 2016 12:00 am
Contact:

Re: Bottom Axix DateTime increment

Post by Torez » Fri May 06, 2016 4:28 am

oh, there is typo, didnt check it. Should be:

Code: Select all

XValueTime := FormatDateTime('dd-mm hh:mm:ss', Now );
Series1.AddXY(XValue, YValue, XValueTime)

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

Re: Bottom Axix DateTime increment

Post by Yeray » Fri May 06, 2016 1:55 pm

Hello,

I've done a simple example trying to reproduce this. I'm using directly TDateTimes in the XValue array instead of using the series Labels, but it seems to work fine for me here:

Code: Select all

uses Series, DateUtils;

var fastLine1: TFastLineSeries;

procedure TForm1.FormCreate(Sender: TObject);
var i: Integer;
    tmpDate: TDateTime;
begin
  Chart1.View3D:=False;
  Chart1.Legend.Visible:=False;

  fastLine1:=Chart1.AddSeries(TFastLineSeries) as TFastLineSeries;
  fastLine1.FillSampleValues(100);

  fastLine1.XValues.DateTime:=True;
  tmpDate:=Now-DateTimeStep[dtOneSecond]*100;
  for i:=0 to fastLine1.Count-1 do
  begin
    tmpDate:=IncSecond(tmpDate);
    fastLine1.XValue[i]:=tmpDate;
  end;

  Timer1.Interval:=1000;
  Timer1.Enabled:=True;

  Chart1.Axes.Bottom.DateTimeFormat:='hh:mm:ss';
end;

procedure TForm1.Timer1Timer(Sender: TObject);
var XValue, YValue, tmpDiff: Double;
begin
  tmpDiff:=fastLine1.YValues.Range/10;
  YValue := fastLine1.YValues.Last + random*(tmpDiff) - (tmpDiff/2);
  XValue := fastLine1.XValues.Last+DateTimeStep[dtOneSecond];//1;
  fastLine1.AddXY(XValue, YValue);
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

Torez
Newbie
Newbie
Posts: 7
Joined: Tue May 03, 2016 12:00 am
Contact:

Re: Bottom Axix DateTime increment

Post by Torez » Sat May 07, 2016 9:47 am

Hallo Yeray,

thank you for answer. DateTimeStep[dtOneSecond] was missing point and some mess in my Chart.
Now is everything working.

But I have ome more issue. Smallest TDateTime step is dtMilliseconds and then dtOneSecond.
Its possible to define 250ms and 500ms as I want to speed up sampling time. I can not figure
out how to define DateTimeStep to 250ms. Please advice.

BR

Tomas

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

Re: Bottom Axix DateTime increment

Post by Yeray » Mon May 09, 2016 8:30 am

Hello Tomas,
Torez wrote:Its possible to define 250ms and 500ms as I want to speed up sampling time. I can not figure
out how to define DateTimeStep to 250ms.
Changing a couple of lines in the code above seems to work fine for me:

Code: Select all

  tmpDate:=Now-DateTimeStep[dtOneMillisecond]*250;

Code: Select all

  Timer1.Interval:=250;
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

Torez
Newbie
Newbie
Posts: 7
Joined: Tue May 03, 2016 12:00 am
Contact:

Re: Bottom Axix DateTime increment

Post by Torez » Sat May 14, 2016 8:42 am

Hallo Yeray,

great, thank you for answer. Things are easy once you have broad perspective :o)

Tomas

Post Reply