The SDL Component Suite is an industry leading collection of components supporting scientific and engineering computing. Please visit the SDL Web site for more information....

Date and Time on Axes

TRChart provides an efficient way to create axes which are labeled by date and time. The range of the axis should therefore be set to the appropriate TDateTime (see Delphi reference) values. The property ScalePropsX[].LabelType (or ScalePropsY[].LabelType, respectively) has to be set to ftDateTime. In order to set up the range of an axis the properties ScaleNX.RangeLow and ScaleNX.RangeHigh (or, ScaleNY.RangeLow and ScaleNY.RangeHigh) can be set most conveniently by using the functions StringToDateTime, or EncodeDate and EncodeTime. Of course, the user may also assign any TDateTime variable or any function which returns a TDateTime value (such as the function Now ) to the RangeXXX properties.

The format of a date/time axis can be adjusted in several respects by changing the property ScalePropsX[].DateFormat (or ScalePropsY[].DateFormat).

Note that date/time axes are restricted by the following limitations:

  • Date/time axes must not be logarithmic (the property ScalePropsX[].Logarithmic (or ScalePropsY[].Logarithmic) is automatically set to false, if ScalePropsX[].LabelType (or ScalePropsY[].LabelType) is set to DateTime).
  • No part of the axis must be negative.
  • The axis must not be decreasing (with decreasing values from left to right, or from bottom to top).
  • The axis may not span a range below 1 second.
  • The first date which can be handled is Jan-1, 0001 (no B.C. !).
  • The last date is Dec-31, 9999.

Note: Delphi 1.0 calculates the date from year 1 whereas Delphi 2.0 calculates it from 1899. To convert a Delphi 1.0 date to a Delphi 2.0 date, subtract 693594.0 from the Delphi 1.0 date.

Example: The following example shows how to set up the range of the x-axis by using the EncodeTime and EncodeDate functions. The ScalePropsX[].DateFormat property is used with the default settings:

RChart1.Scale1X.LabelType := ftDateTime;
RChart1.Scale1X.RangeLow := EncodeDate (1968,2,23) + EncodeTime (0,0,0,0);
RChart1.Scale1Y.RangeHigh := EncodeDate (1968,2,25) + EncodeTime (18,00,0,0);

The result may look like this (depending on the Scale1X.DateFormat settings):

Last Update: 2012-Oct-20