Page 1 of 1

Showing timestamp on Horizontal axis with AddArray

Posted: Thu Jun 10, 2010 7:30 am
by 10554272
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

Re: Showing timestamp on Horizontal axis with AddArray

Posted: Thu Jun 10, 2010 8:00 am
by narcis
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!

Re: Showing timestamp on Horizontal axis with AddArray

Posted: Thu Jun 10, 2010 8:31 am
by 10554272
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

Re: Showing timestamp on Horizontal axis with AddArray

Posted: Thu Jun 10, 2010 9:07 am
by yeray
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.

Re: Showing timestamp on Horizontal axis with AddArray

Posted: Thu Jun 10, 2010 9:55 am
by 10554272
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

Re: Showing timestamp on Horizontal axis with AddArray

Posted: Fri Jun 11, 2010 12:43 am
by 10554272
Any idea anybody how to show a graph and place my own time values for each point on the horizontal axis?

Re: Showing timestamp on Horizontal axis with AddArray

Posted: Fri Jun 11, 2010 3:33 am
by 10554272
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

Re: Showing timestamp on Horizontal axis with AddArray

Posted: Fri Jun 11, 2010 11:00 am
by yeray
Hi,

I'm glad to see you've found how to do it.