Page 1 of 1

Bottom Axix DateTime increment

Posted: Fri May 06, 2016 4:25 am
by 16478202
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

Re: Bottom Axix DateTime increment

Posted: Fri May 06, 2016 4:28 am
by 16478202
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)

Re: Bottom Axix DateTime increment

Posted: Fri May 06, 2016 1:55 pm
by yeray
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;

Re: Bottom Axix DateTime increment

Posted: Sat May 07, 2016 9:47 am
by 16478202
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

Re: Bottom Axix DateTime increment

Posted: Mon May 09, 2016 8:30 am
by yeray
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;

Re: Bottom Axix DateTime increment

Posted: Sat May 14, 2016 8:42 am
by 16478202
Hallo Yeray,

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

Tomas