Visit Gigasoft's Web Site
ProEssentials v7 Help

Chapter 6: Date/Time Handling

 

The Graph and Scientific Graph have different methods of getting dates along the x axis.

 

We will first discuss the Scientific Graph Object and next the Graph Object.

Scientific Graph Objects with Dates along X Axis

The Scientific Graph has an improved mechanism for handling date/time formatted data. It uses XData or XDataII to store serially formatted data. Using correctly formatted data and setting the DateTimeMode property to reflect that format will cause the normal numerical x axis to be replaced with a linear date/time calendar axis. This date/time scale is dynamic and will adjust in structure based upon the date/time range currently shown. This allows the end-user to zoom inward and always have an appropriate x axis scale to match the range of time graphed.

 

The date format is constructed from integer and decimal portions. The integer portion is the number of days from 12/31/1899. The decimal portion is the fraction of day.

 

If your date/time data is not in a compatible format, ProEssentials includes the function PEcreateserialdate to create the proper format.

 

Above we mentioned both XData and XDataII. The property you will use depends on the type of date/time data you are graphing.

 

If your data includes Date and Time:

Use XDataII for double precision storage and set UsingXDataII equal to TRUE.

 

If your data includes only Dates:

Use XData for single precision storage.

 

The following VB6 example code show how to use DateTimeMode.

 

'** VB4 Example Code **'

Pesgo1.XDataII(0, 0) = Now 'Current date and time

Pesgo1.XDataII(0, 1) = Now + 20 'Now + 20 days

Pesgo1.XDataII(0, 2) = Now + 40 'Now + 40 days

Pesgo1.XDataII(0, 3) = Now + 60 'Now + 60 days

Pesgo1.UsingXDataII = True

Pesgo1.DateTimeMode = 1

Pesgo1.PEreinitialize()

Pesgo1.PEresetimage(0, 0)

 

The above example code produces the following graph.

 

 

The Scientific Graph has to show all time within its range (continuous time). All 24 hours of the day and all days of the week will show between the start date/time on the left and the ending date/time on the right. If your data is discontinuous, (from 8am to 5pm Monday through Friday), the Graph Object's date/time mechanism may be a better choice.

 

Note that the use of DateTimeMode is not compatible with ManualXAxisTicknLine. If you need a specific looking date/time scale, you will have to manually produce this scale as described in Chapter 6 Creating Custom Scales.

 

Within the demo and example projects, see example 106.

 

Graph Objects with Dates along X Axis

With the Graph Object, you have two choices.

  1. Simply assign PointLabels for each data-point.

  2. Use the DateTimeMode feature.

1. Assigning PointLabels

Data-point labels are text-strings, so assigning a date is accomplished by passing a string formatted as desired. For example, "3/8/99" or "Mar 8, 99" could be passed as a point label. These point labels are placed below the x axis and also below the corresponding data-point. If your graph has many data-points, you may want to control the frequency and first point label location. In this case, refer to Chapter 6 Graph Object's X Axis in this chapter for more information.

2. Using DateTimeMode

Using DateTimeMode with the Graph Object is a specialized mechanism to plot date/times along the x axis. This feature can handle discontinuous time data (for example, time values from 8am to 5pm Monday through Friday) but data needs to be quantified. This mode will automatically and dynamically construct a linear date/time calendar along the x axis. As the user zooms, this scale will change in structure to best accommodate the range of time.

 

There are several related properties which need to be used to implement this feature:

 

DeltaX

DeltasPerDay

StartTime

AutoXData

XData, XDataII, UsingXDataII

 

You can quickly see there's more going on than just setting PointLabels.

 

The first thing you need to know is if you are dealing with intra-day, daily, weekly, or monthly data. Lets start with intra-day, this is the most complex but is also the most common.

 

For Intra-Day Data

DeltaX needs to be set to the number of minutes between each data point. Common values will be 1, 2, 5, but any value will work. 1 meaning 1 minute, 2 meaning 2 minutes, and so on. Thus you can see what we mean by quantified. Each data point represents the value for a quantity of time.

 

DeltasPerDay needs to be set to the number of data points in a day. Each day will have to have the same number of data points and this is one of the complex aspects of implementing DateTimeMode with the Graph Object. If your DeltasPerDay is set to 300, then you need 300 pieces of YData for each day. No more. No less. If you don't have a valid data value for a particular time segment, assign a NullDataValue to this location.

StartTime represents a Date/Time value of the first data point in the chart. This is a serially formatted double precision floating point value similar to the format that VB and Delphi use to represent Date/Times. If not using VB or Delphi, you can use the function PEcreateserialdate to create a date/time value in the proper format.

 

AutoXData is optional and recommended. If you don't manually assign XData, this feature will automatically generate XData during the object's initialization. If dealing with Intra-Day data, be sure to set UsingXDataII to TRUE. Set AutoXData to 0 (PEAXD_ALLDAYS) for ProEssentials to generate XData which includes all days of the week. Set AutoXData to 1 (PEAXD_NOSATORSUN) for ProEssentials to generate XData which skips Saturdays and Sundays.  Note you can only use this feature if you pass y data to match the structure of the automatically generated x data. This structure should be evident after studying the example code below.

 

XData, XDataII can be set manually. ProEssentials will look to see if XData or XDataII exists. If it does, it will not use AutoXData to automatically generate XData. If your data skips days such as Monday and Tuesday, then you will have to manually construct XData. Look at the example code below for an example of creating XData manually.

 

UsingXDataII should be set to TRUE for Intra-Day data and left FALSE for daily, weekly, or monthly data.

 

Following is an example of using DateTimeMode and AutoXData.

 

'** Define how much data is in chart **'

Pego1.Subsets = 1

Pego1.Points = 3000

 

'** Set Date Time Handling related properties **'

Pego1.DeltaX = 2 ' 2 minutes between data points

Pego1.DeltasPerDay = 210 ' 210 data points in one day

Pego1.StartTime = CLng(Now) + 0.333333333333333 ' Today at 8:00 am

Pego1.UsingXDataII = True ' Using double precision x data, XDataII

Pego1.AutoXData = 0 ' Include Saturdays and Sundays

 

'** pass random data **'

For p = 0 To 2999

    Pego1.YData(0, p) = 5 + (Sin(p * 0.024))

Next p

 

'** Enable DateTimeMode **'

Pego1.DateTimeMode = PEDTM_VB  '(1)

 

The above code produces the following image. Note that it's not important that the last day has DeltasPerDay data points, just the starting day and all days between the first and last day.

 

 

Now lets repeat the example but this time generate XDataII manually. Study this example thoroughly if you will be constructing your own XData manually.

 

Dim i As Integer '** counter to keep track of data values per day

Dim d As Double  '** used as date value

 

'** Define how much data is in chart **'

Pego1.Subsets = 1

Pego1.Points = 3000

 

'** Set Date Time Handling related properties **'

Pego1.DeltaX = 2            ' 2 minutes between data points

Pego1.DeltasPerDay = 210    ' 210 data points in one day

Pego1.StartTime = CLng(Now) + 0.333333333333333 ' Today at 8:00 am

Pego1.UsingXDataII = True   ' Using double precision x data

d = CLng(Now) ' Initialize d with the starting day, integer value only.

 

i = 0

For p = 0 To 2999

   Pego1.YData(0, p) = 5 + (Sin(p * 0.024))

   Pego1.XDataII(0, p) = d + 0.333333333333333 + (((i * 2#) / 60#) / 24#)

   '** 2 represents data every two minutes, same as DeltaX

   '** 60 represents 60 minutes in an hour

   '** 24 represents 24 hours in a day

   i = i + 1 ' increment data per day counter

   If (i >= 210) Then ' 210 is DeltasPerDay as above

      i = 0 ' reset data per day counter

      d = d + 1 ' increment day

   End If

Next p

 

'** Enable DateTimeMode **'

Pego1.DateTimeMode = PEDTM_VB ' (1)

 

The above code produces the same image as the first example did.

For Daily, Weekly, Monthly Data

These types of charts are a little easier than the Intra-Day chart.

 

Set DeltaX as follows...

 

DeltaX

Type of Data

- 1 (negative 1)

Daily

- 2

Weekly

- 3

Monthly

 

DeltasPerDay is ignored.

 

UsingXDataII can be left the default state FALSE. Double precision is not needed for Daily, Weekly, or Monthly data.

 

StartTime, AutoXData, XData are used as above.

 

For Daily Data, make sure you have one data point for each day. If there is a day with no data, assign the NullDataValue to this data point. You do not have to have a full year's worth of data points for the last year shown, only the first year and every year between the first and last. If a leap year exists in your data, you need to account for this in your data and have an extra data point as necessary.

 

For Weekly Data, make sure you have 52 weekly data points per year. You do not have to have 52 data points in the last year shown, just the first year and every year between the first and last.

 

For Monthly Data, make sure you have 12 monthly data points per year. You do not have to have 12 data points in the last year shown, just the first year and every year between the first and last.

 

Below is an example of a Daily Data Chart.

 

'** Define how much data is in chart **'

Pego1.Subsets = 1

Pego1.Points = 300

 

'** Set Date Time Handling related properties **'

Pego1.DeltaX = 2 ' 2 minutes between data points

Pego1.StartTime = CLng(Now) ' Today at 8:00 am

Pego1.AutoXData = 0 ' Include Saturdays and Sundays

For p = 0 To 299

   Pego1.YData(0, p) = 5 + (Sin(p * 0.024))

Next p

 

'** Enable DateTimeMode **'

Pego1.DateTimeMode = 1

 

The resulting image is shown below.

 

 

As with the Scientific Graph Object, note that the use of DateTimeMode is not compatible with ManualXAxisTicknLine. If you need a specific looking date/time scale, you will have to manually produce this scale as described in Question 22.

 

Within the demo and example projects, see examples 016, and 030.