Page 1 of 2

Show X axis in seconds or minutes or hours?

Posted: Wed Jun 27, 2007 5:08 am
by 9349911
Hi !

Our x axis normally displays seconds. But you can imagine that it is difficult for an user to think about how many minutes / hours are 13567 seconds. :wink:

So how can I switch the X achis labels to show another format:
- minutes (example: 5682 seconds = 94m42s or 94,7)
- hours (example: 5682 seconds = 1h34m42s or 1h34,7m or 1,5783)

Would it be possible that you give me a short example how to calculate and display these formats? It would be ok if the example shows only the two minute formats. I think calculating the hours isn´t so difficult then.

Posted: Wed Jun 27, 2007 7:42 am
by narcis
Hi Dominik,

Here you can use axes DateTimeFormat property as told in Tutorial 4 - Axis Design. You'll find the tutorials at TeeChart's program group.

You can also complete your parsing using OnGetAxisLabels event. You'll also find examples in tutorial 4.

Posted: Wed Jun 27, 2007 8:00 am
by 9349911
Hi Narcís,

well I tried to set the bottom axis to the format "mm:ss".

The result ...
Seconds are always zero and the mnutes start with 6 and not with 0.

I unselect the auto checkbox at the minimum tab. At the maximum tab it is set to auto.

What´s wrong here?

Posted: Wed Jun 27, 2007 8:03 am
by narcis
Hi Dominik,

Have you set Series.XValues.DateTime:=true? If so, could you please send us a simple example project we can run "as-is" to reproduce the problem here?

You can either post your files at news://www.steema.net/steema.public.attachments or at our upload page.

Thanks in advance.

Posted: Wed Jun 27, 2007 8:13 am
by 9349911
Hi !

>Have you set Series.XValues.DateTime:=true?
Yes

>If so, could you please send us a simple example project we can run "as-is" to reproduce the problem here?
See ...
Received Axis Demo 2.zip Content Type application/x-zip-compressed Length 24261

Posted: Wed Jun 27, 2007 8:43 am
by narcis
Hi Dominik,

Thanks for the example.

This is most likely because of the way you populate series. Using FillSampleValues(NumValues) uses integer values (from 0 to NumValues-1) for series' X values. Please read how TDateTime works here. This will help you setting x values to be displayed as you request.

Thanks in advance.

Posted: Wed Jun 27, 2007 8:46 am
by 9349911
Hi Narcís,
Using FillSampleValues(NumValues) uses integer values (from 0 to NumValues-1) for series' X values
Well that´s the way we use it in our application. There is only one difference ... We use double values instead of integer.

So I must convert all X values to TDateTime !?

Is there an easier way ?

Posted: Wed Jun 27, 2007 8:55 am
by narcis
Hi Dominik,

As told in the TDateTime documentation I pointed you to, the integer part of a TDateTime value only determines the date. If you want those values to be in mm:ss format you need to specify the decimal part. You can see an example doing this:

Code: Select all

procedure TForm1.Button1Click(Sender: TObject);
begin
  Label1.Caption:=FloatToStr(Now);
end;
There's no need to convert values to TDateTime you can assign them as doubles, for example:

Code: Select all

Series1.AddXY(Now,Y);

Posted: Wed Jun 27, 2007 9:19 am
by 9349911
Hi Narcís,

well maybe I´m blinded today ... I don´t get it working.

Could you please make a very simple demo for me with this terms:
- x values are double values starting from 0 to something (for example 0, 0.2, 0.4, 0.6, 0.8, 1, 1.2, and so on)
- if you switch to mm:ss view every whole-number is one second. So in the above example 0.6 are 0.6 seconds.

Many thanks !

Posted: Wed Jun 27, 2007 9:50 am
by narcis
Hi Dominik,

You can try executing this code:

Code: Select all

procedure TForm1.FormCreate(Sender: TObject);
const second=1/(24*3600); //Fractional number representing one second in TDateTime
var i: Integer;
    x: double;
begin
  x:=0;

  for i:=0 to 10 do
  begin
    Series1.AddXY(x,random);
    x:=x+second;
  end;
end;

procedure TForm1.Button1Click(Sender: TObject);
begin
  Chart1.Axes.Bottom.DateTimeFormat:='hh:mm:ss';
  Series1.XValues.DateTime:=not Series1.XValues.DateTime;
end;
Hope it helps!

Posted: Wed Jun 27, 2007 10:13 am
by 9349911
Hi Narcis,

we come closer :roll:

Code: Select all

Chart1.Axes.Bottom.DateTimeFormat:='hh:mm:ss';
This works ok.

Code: Select all

Chart1.Axes.Bottom.DateTimeFormat:='mm:ss';
This will start with 12:00 and mm is always 12 :shock:

And the second problem:

Code: Select all

procedure TForm1.FormCreate(Sender: TObject);
const second = 1 / (24 * 3600); //Fractional number representing one second in TDateTime
Const Step   = 0.2;
var i: Integer; 
    x: double; 
begin 
  x := 0;

  for i := 0 to 100 do
  begin 
    Series1.AddXY(x,random); 
    x := x + (Step * second);
  end;
end;
Our normal X Axis is calculated similar to this:
x := 0;
Series.add ....
x := x + Step; // <- Step is for example 0.2 = 200MilliSeconds

To get your code working I have to use this line of code:

Code: Select all

x := x + (Step * second);
If I switch to the time axes, I got 00:00:20 = 20 seconds and thats correct.
But if I switch back to the normal view I have values from 0 to 0,000 :wink:

This is because second is a really small value ...

Hope to get this solved :roll:

Posted: Wed Jun 27, 2007 1:34 pm
by narcis
Hi Dominik,
his will start with 12:00 and mm is always 12
Can you please send us a simple example project we can run "as-is" to reproduce the problem here?
To get your code working I have to use this line of code:
Code:
x := x + (Step * second);


If I switch to the time axes, I got 00:00:20 = 20 seconds and thats correct.
But if I switch back to the normal view I have values from 0 to 0,000 Wink

This is because second is a really small value ...
This is quite strange as it works fine for me here. Every loop x value is incremented by one second. Anyway, yes, as I told you, hours, minutes, seconds, ... Are fractions of a day and thus represented by the decimal part of a double value.

Posted: Wed Jun 27, 2007 1:45 pm
by 9349911
Hi Narcis,

at first ... Thx for your really great support job !!

I will make a small example project, tomorrow. Maybe I can include a short WMV video which shows you my results.

You wil hear from me.

Posted: Thu Jun 28, 2007 5:50 am
by 9349911
Hi Narcís,

I´ve just uploaded a small sample application to your server:
Received TimeAxis Demo.zip Content Type application/x-zip-compressed Length 33937
Let me explain some usecases where I have trouble...

1) Always recalculate the X values
As you can see in the source, I have always to recalculate the x values if I switch between the normal and the time axis view. This is because the timeaxis needs the

Code: Select all

const second=1/(24*3600);
for a correct display.
If I switch back (and don´t recalculate the X values) then I got very very small values for the normal view. You can try this if you use this code for button2:

Code: Select all

procedure TForm1.Button2Click(Sender: TObject);
Var i: Integer;
begin
  Series1.XValues.DateTime          := False;
end;
2) Axes.Bottom.DateTimeFormat "mm:ss"
If you set Chart1.Axes.Bottom.DateTimeFormat to "mm:ss" the time always starts with 12:00. Only switch the combo in the demo and press "Set X to time" again.
And the next problem is ... after 12:00 you will have 12:30 and then it switched back to 12:00.
It´s a little bit confusing :shock:

3) Axes.Bottom.DateTimeFormat "ss"
This will show values from 00 to 59, go back to 00 and so on ...
Changing DateTimeFormat to ssss don´t bring better results.

4) floating seconds and / or minutes
I have no idea how to set up the axis to see the time in this format:
94,7 (which means 94m42s). Or something like this: 1,5783 (which means 1h34m42s).
How can I do this?

5) adding characters instead of ":"
It would be a better to see 1h34m42s instead of 1:34:42. But no idea how to set up the axis, too.

It would be great if you can enhance my short demo in that way, that I can switch between the different views with correct results. I think this is also interesting for other people who need a time axis ...

So it would be great if I can switch between this time formats:
  • hh:mm:ss
    hhhmmmsss (See point 5)
    mm:ss
    mmmsss (See point 5)
    sss
(See point 5)

Some hints to the format ss ... This is not really important because it is the normal view. Keep in mind that we always use seconds for the x axis.
And our x axis always start from 0 or from 1!

Hope on any help :roll:

And one last question ...
Is it possible to reduce times like 00:00:01 to 1 or 00:02:41 to 2:41? Is think this would look better for the users.

Posted: Fri Jun 29, 2007 10:23 am
by 9349911
Hi Narcís,

do you have some news for me?
Did you take a look at my sample application ?