Page 1 of 2

GetNextAxisLabel event not fired!

Posted: Fri Aug 11, 2006 4:40 pm
by 9790349
Hi,

When GetAxisLabel event is set the GetNextAxisLabel event not fire!

I used GetAxisLabel to convert datetime axis label from UTC to LocalTime.

Code: Select all

 with TChart1.Axes.Bottom do
  begin
      Labels.DateTimeFormat := 'yyyy.MM.dd HH:mm:ss';
      Labels.MultiLine := true;
  end;

Code: Select all

procedure TWinForm.TChart1_GetNextAxisLabel(sender: System.Object; e: Steema.TeeChart.GetNextAxisLabelEventArgs);
var
  value : Double;
  date : System.DateTime;
  ax : Steema.TeeChart.Axis;
  a : integer;
  t : TimeSpan;
  d1, d2 : datetime;
  LabelOK : Boolean;
begin
  LabelOK := False;

  ax := steema.teechart.axis( sender );

  if (ax.Equals(tChart1.Axes.Bottom)) then
  begin
    d1 := DateTime.fromoadate( ax.Maximum);
    d2 := datetime.fromoadate( ax.Minimum);
    t:= d1.Subtract(d2);
    a := convert.ToInt32(t.TotalMinutes) div 15;

    e.Stop := False;

    if first then
    begin
      value := e.LabelValue;
      date := DateTime.FromOADate(value);
      Debug.Write(date.ToString);
      newDate := DateTime.Create(date.Year, date.Month, date.Day, date.Hour, 0, 0);

     debug.Write('Newdate1 = ' + newdate.ToString);

      if (date.Minute >= 15) then
        newDate := newDate.AddMinutes(15)
      else if (date.Minute >= 30) then
          newDate := newDate.AddMinutes(30)
        else if (date.Minute >= 45) then
            newDate := newDate.AddMinutes(45);

      first := False;

    end
    else
      newDate := newDate.AddMinutes(15);

   if e.LabelIndex = 0 then
   begin
     e.LabelValue := value;
     LabelOK := True;
   end;

   if (e.LabelIndex > 0) and (e.Labelindex <= a + 2) then
   begin
     e.LabelValue := newDate.ToOADate();
     LabelOk := True;
   end;

   if e.LabelIndex = a+3 then
   begin
     e.LabelValue := ax.Maximum;
     LabelOK := True;
   end;

   if not LabelOK then
   begin
     e.Stop := true;
     first := true;
   end;

  end;    
end;

Code: Select all

procedure TWinForm.TChart1_GetAxisLabel(sender: System.Object; e: Steema.TeeChart.GetAxisLabelEventArgs);
var
  axis : Steema.TeeChart.Axis;
  datValue : System.DateTime;
begin
  axis := Steema.TeeChart.Axis( sender );
  if (sender = axis.Chart.Axes.Bottom) then
  begin
    // note - e.LabelText must initially hold complete datetime, not only time part!
    datValue := System.DateTime.Parse(e.LabelText);
    e.LabelText := datValue.ToLocalTime.ToString('MM.dd HH:mm:ss');
  end;
end;

Please response me as soon as possible!

Best regards,

Gabor Varga

Posted: Mon Aug 14, 2006 9:43 am
by Chris
Hello,
When GetAxisLabel event is set the GetNextAxisLabel event not fire!
This is because GetAxisLabel only works with custom axes labels and GetNextAxisLabel only works with default axes labels. As soon as you specify labels in one of the Series.Add() overloads then your chart is working with custom axes labels and so the GetNextAxisLabel event will not be fired. On the other hand, the GetAxisLabel event will only be fired if you add custom axes labels.

Posted: Mon Aug 14, 2006 10:07 am
by 9790349
Hi,

Thanks for your reply!

May I ask you to help me to solve the current problem:

I have Series with UTC DateTime XValues to solve daylightsaving problem

- I want to show Labels of Bottom Axis in local time (I used GetAxisLabel)
- I want to set 15 min time intervals (like as in "Time Axis Problem" topic you did)

How can I do that if I cannot use GetAxisLabel and GetNextAxisLabel event at the same time?

Best regards,

Gabor Varga

Posted: Mon Aug 14, 2006 10:09 am
by Chris
Hello,
How can I do that if I cannot use GetAxisLabel and GetNextAxisLabel event at the same time?
Easy. Convert your DateTime instances to localtime (DateTime.ToLocalTime) *before* you add them to your chart. Then use the GetNextAxisLabel event as specified.

Posted: Mon Aug 14, 2006 10:34 am
by 9790349
Hi,
Convert your DateTime instances to localtime (DateTime.ToLocalTime) *before* you add them to your chart.
Do you mean convert DateTime values in DataSet?

It is not good for me because at daylight saving time I will have a following problems:

- There will a break of continuity in line when 2AM will be 3AM. (CET -> CEST)
- I will lost data when 3AM will be 2AM! (there is twice 2AM at that day) (CEST->CET)

I always want to have a continual Series (lines)!

Best regards,

Gabor Varga

Posted: Mon Aug 14, 2006 10:39 am
by Chris
Hello,

Do you mean convert DateTime values in DataSet?

It is not good for me because at daylight saving time I will have a following problems:
No, I mean that you don't use the Series.DataSource method and you do iterate through your DataSet and use Series.Add to add your data to the chart.

As for daylight saving then you already have the same problem using the code you sent below in the GetAxisLabel event, as the DateTime.ToLocalTime() method is also used there.

You might like to read up on UTC, localtime and daylight saving a little more thoroughly; a start might be here:
http://blogs.msdn.com/bclteam/archive/2 ... 67119.aspx

Posted: Mon Aug 14, 2006 10:53 am
by 9790349
Hi,

I used before CheckDatasource method to refresh my Series.

How can I refresh the Series when I use Series.Add()? Clear and and all datapoints again? Is it not slower than CheckDatasource method?

I have cyclic data, cycletime is 6 secs, time range is max a week...

Best regards,

Gabor Varga

P.S. Sorry for being a "vampire" but it is a cardinal question for me. :oops:

Posted: Mon Aug 14, 2006 12:31 pm
by Chris
Hello,
How can I refresh the Series when I use Series.Add()? Clear and and all datapoints again? Is it not slower than CheckDatasource method?
No, it won't be slower as this is exactly what CheckDatasource() method does internally anyhow.
P.S. Sorry for being a "vampire" but it is a cardinal question for me.
Not to worry, I forgive you :wink:

Posted: Wed Aug 16, 2006 3:46 pm
by 9790349
Hi,

I think it is not so easy...

Set yout time zone to Budapest (CEST, GMT+1) and try the following code:

Code: Select all

procedure TWinForm.Button1_Click(sender: System.Object; e: System.EventArgs);
var
  length,i : Integer;
  dt_utc, dt_loc : datetime;
  rnd : system.Random;
begin
  Line1.Clear;
  length := 180;
  dt_utc := DateTime.Create(2006, 03, 26, 0, 0, 0 );
  rnd := system.Random.Create;
  i := 0;
  while (i < length) do
  begin
    dt_loc := dt_utc.ToLocalTime;
    line1.Add(dt_loc, rnd.NextDouble);
    dt_utc := dt_utc.AddMinutes(1);
    inc( i );
  end;

end;
You will get the following labels: (on TChart1.Axes.Bottom)

...
2006.03.26 01:45
2006.03.26 02:00 <- Wrong
2006.03.26 02:15 <- Wrong
2006.03.26 02:30 <- Wrong
2006.03.26 02:45 <- Wrong
2006.03.26 03:00 <- OK
...

I think the solution is the combination of GetAxisLabel and GetNextAxisLabel as I wanted to solve this problem. Is it not possible to enable GetAxisLabel on custom axes labels for future releases? (Or have you any another idea to solve this problem?)

Best regards,

Gabor Varga

Posted: Wed Aug 16, 2006 4:18 pm
by 9790349
Hi,

I think the following will be very useful:
OK, I've added a new property to the AxisLabels class called 'LabelsAsLocalTime' which will become available in the maintenance release due out in September.
I think it will solve my problem, too. (But have you got some idea how to solve my problem until the next release will be out?)

Best regards,

Gabor Varga

Posted: Thu Aug 17, 2006 6:20 am
by Chris
Hello,
But have you got some idea how to solve my problem until the next release will be out?
What, exactly, is your problem?

Posted: Thu Aug 17, 2006 9:15 am
by 9790349
Hi,

Series data in UTC (to have a continual line), Label of Bottom Axis in Local time with 15 min intervals (for example: 7:00, 7:15, 7:30 etc)

Best regards,

Gabor Varga

Posted: Thu Aug 17, 2006 9:58 am
by Chris
Hello,

Two alternatives:
1. Convert your DateTime instances to localtime (DateTime.ToLocalTime) *before* you add them to your chart. Then use the GetNextAxisLabel event as specified.
2. Iterate through your data and using logic similar to that exposed in the GetNextAxisLabel event and add in the relevant axis labels as strings using one of the Series.Add overloads which takes a label (a string).

Posted: Thu Aug 17, 2006 10:01 am
by Chris
Hello,
2. Iterate through your data and using logic similar to that exposed in the GetNextAxisLabel event and add in the relevant axis labels as strings using one of the Series.Add overloads which takes a label (a string).
You could even add in null points, that is, with Color.Transparent, and the string as the axis label you require.

Posted: Tue Aug 22, 2006 8:37 am
by 9790349
Hi,

May I ask you to send me a daily build from TeeChart 2 for .NET 1.1 which already have 'LabelsAsLocalTime' feauture? (It does not matter that it is not stable, my software is in beta state too.)

Please response me ASAP!

Thanks in advance,

Gabor Varga