Showing timestamp on Horizontal axis with AddArray

TeeChart VCL for Borland/CodeGear/Embarcadero RAD Studio, Delphi and C++ Builder.
Post Reply
Track1
Newbie
Newbie
Posts: 13
Joined: Mon Sep 21, 2009 12:00 am

Showing timestamp on Horizontal axis with AddArray

Post by Track1 » Thu Jun 10, 2010 7:30 am

I can't seem to find an answer to what I hope is a simple problem
I have a chart with 3 series
I have three Arrays[0..255] each holding data points for the plot
I want to move (scroll) the chart contents over time by removing the oldest, moving others down, and with the latest value added at high(Myarray) (essentially First In First out)
All of the above works, but I want to plot these arrays but with a timestamp on the horizontal axis showing the time points
To show the moving chart, I am using
Chart1.Series[0].Clear;
Chart1.Series[0].AddArray(MyArray1);

What do I have to do to show a timestamp on the horizontal axis for each recorded point in the array?

Many thanks

Narcís
Site Admin
Site Admin
Posts: 14730
Joined: Mon Jun 09, 2003 4:00 am
Location: Banyoles, Catalonia
Contact:

Re: Showing timestamp on Horizontal axis with AddArray

Post by Narcís » Thu Jun 10, 2010 8:00 am

Hi Track1,

For that you just need to set DateTime property to true in your series, for example:

Code: Select all

Chart1.Series[0].XValues.DateTime:=True;
Hope this helps!
Best Regards,
Narcís Calvet / Development & Support
Steema Software
Avinguda Montilivi 33, 17003 Girona, Catalonia
Tel: 34 972 218 797
http://www.steema.com
Image Image Image Image Image Image
Instructions - How to post in this forum

Track1
Newbie
Newbie
Posts: 13
Joined: Mon Sep 21, 2009 12:00 am

Re: Showing timestamp on Horizontal axis with AddArray

Post by Track1 » Thu Jun 10, 2010 8:31 am

Re:
Chart1.Series[0].XValues.DateTime:=True;

Thanks Narcis, but I already tried that, still there is only zero on the H axis:

IdleProcessingTimeArray : Array[0..255] of Double;
SocketProcessingTimeArray : Array[0..255] of Double;
XformProcessingTimeArray : Array[0..255] of Double;

...

chart1.Series[0].Clear;
chart1.Series[1].Clear;
chart1.Series[2].Clear;

chart1.Series[0].XValues.DateTime := True;
Chart1.BottomAxis.DateTimeFormat := 'hh:mm:ss' ;

chart1.Series[0].ADDArray(SocketProcessingTimeArray);
chart1.Series[1].AddArray(XformProcessingTimeArray);
chart1.Series[2].AddArray(IdleProcessingTimeArray);

Many thanks for any suggestions
Attachments
10-06-2010 6-30-22 PM.png
10-06-2010 6-30-22 PM.png (26.32 KiB) Viewed 9348 times
10-06-2010 6-19-45 PM.png
10-06-2010 6-19-45 PM.png (7.13 KiB) Viewed 9340 times

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

Re: Showing timestamp on Horizontal axis with AddArray

Post by Yeray » Thu Jun 10, 2010 9:07 am

Hi Track1,

That's normal because you have Integers as DateTime in the XValues and you are formatting them as 'hh:mm'. Let me explain:
There are two AddArray methods available. Here there are their definitions:

Code: Select all

    Function AddArray(Const Values:Array of TChartValue):Integer; overload;
    Function AddArray(Const XValues, YValues:Array of TChartValue):Integer; overload; 
As you are using the first one, only adding the YValues, the XValues are 0, 1, 2, 3,... and translating them to DateTime, it's "30/12/1899 00:00:00" for the 0, "31/12/1899 00:00:00" for the 1,...
And formatting these DateTimes to 'hh:mm', you always get "00:00".

So I'd recommend you to use the second AddArray method.
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

Track1
Newbie
Newbie
Posts: 13
Joined: Mon Sep 21, 2009 12:00 am

Re: Showing timestamp on Horizontal axis with AddArray

Post by Track1 » Thu Jun 10, 2010 9:55 am

Thank you Yeeray, but still the problem exists

I am now using the overload method

RecAtTimeArray : Array[0..255] of Double; // (stores 'Now')
IdleProcessTimeArray : Array[0..255] of Double;
...

//move other values down like before then add new value:
//Each time I update the array I add the date time as well in the second array
RecAtTime(high(recAtTime)) := Now;
IdleProcessTimeArray(high(IdleProcessTimeArray)) := IdleProcessTime;


Chart1.Series[0].Clear;
Chart1.Series[0].AddArray(RecATTimeArray, IdleProcessTimeArray);

I think the system adds multiple time stamps (255 of them) for each and every IdleProcessTimeArray array point


Result shown. Many thanks for your support
Attachments
10-06-2010 7-52-01 PM.png
10-06-2010 7-52-01 PM.png (9.52 KiB) Viewed 9338 times

Track1
Newbie
Newbie
Posts: 13
Joined: Mon Sep 21, 2009 12:00 am

Re: Showing timestamp on Horizontal axis with AddArray

Post by Track1 » Fri Jun 11, 2010 12:43 am

Any idea anybody how to show a graph and place my own time values for each point on the horizontal axis?

Track1
Newbie
Newbie
Posts: 13
Joined: Mon Sep 21, 2009 12:00 am

Re: Showing timestamp on Horizontal axis with AddArray

Post by Track1 » Fri Jun 11, 2010 3:33 am

OK, I worked it out

I must user the overloaded method for every series I add to the chart
Series1.AddArray(RecTimeArray, MyData1Array);
Series2.AddArray(RecTimeArray, MyData2Array);
Series3.AddArray(RecTimeArray, MyData2Array);

Adding any series, (not just the one set for XValues.DateTime := True), without adding both arrays, regardless of the order they are added (first, last etc), stops the time display working (shows all zero's).

Regards

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

Re: Showing timestamp on Horizontal axis with AddArray

Post by Yeray » Fri Jun 11, 2010 11:00 am

Hi,

I'm glad to see you've found how to do 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

Post Reply