Reference > Glossaries > Using Date and Time Axes

Using Date and Time Axes

Timeseries data from Excel or from a database query is often held internally as floating-point numbers where the integer part represents the date (the number of days elapsed since 1900) and the decimal part the time of day. This scheme is accurate to around 2 sec with normal floating-point precision and is equivalent to the OLE date format.

For example day number 35414 is actually 15/12/96 (in DD/MM/YY format) so 35414.5 would be 15/12/96 12:00, as times run from midnight to 23:59 spanning the range 0-1. SharpPlot can accept ‘date’ and ‘time’ styles (or both together) on either the X or Y axes, and will format the labels accordingly. The dates are shown by default in the format of your current Windows ‘short date’ setting and the times are normally shown as ‘HH:MM’ on a 24-hour clock.

Value ... Style ... Shown as
35414.25 ... (default) ... 35400
35414.25 ... date ... 15/12/96
35414.25 ... time ... 06:00
35414.25 ... date,time ... 15/12/96 06:00

For more detailed control over the presentation of the date/time combination, you can use the XDateFormat and XTimeFormat properties, for example to label tickmarks ‘Jan-01’ ‘Feb-01’ .... ‘Dec 02’ (in your local language) a suitable format would be “MMM-yy”.

The X-axis will also accept integers in the range 19000000 to 20991231 and (if the x-style is one of ‘date/annual/monthly’) treat these as if they are OLE date values. This may be convenient if you have imported your dates from an old time-series database, as this was a very common format in many database designs.

The tick-mark interval for both X and Y axes is normally a simple integer value, but for axes which include the ‘time’ style it is interpreted as a number of hours, so to get ticks every 6 hours you should set ‘Xtick’ to 6 rather than 0.25 (which would be the normal interpretation of this setting). Default tickmarks normally look for intervals which divide into 10; for time-based axes the choice is made between values which divide into 12 which gives a much better selection of intervals.

Calendar styles

In addition to ‘date’ you can set the x-axis (only) to style ‘annual’ which will put tickmarks at the year boundaries (so the tick spacing will be very slightly irregular). In this case the tick interval gives the number of years, so to mark decades you could use:

SharpPlot.XAxisStyle = XAxisStyles.Annual;
SharpPlot.SetXTickMarks(10);

This style would very likely go along with ‘MiddleLabels’ to get the labels written between the tick marks. The style ‘Monthly’ works in a similar way – in this case the tickmark setting is the interval between months.

See also ...

XDateFormat Property | YDateFormat Property


Send comments on this topic
© Dyalog Ltd 2013