Additional ticks in DateTimeAxis

Feb 23, 2012 at 11:40 AM
Edited Feb 23, 2012 at 11:41 AM

During my first experiments with OxyPlot I found the following detail:

When using a scale of one or ten years the scale is error free.
Example: http://oxyplot.iam.at/examplesvg.aspx?title=DateTimeAxisFiala.DateTime+axis1+Fiala

But when using a scale of 100 years additional and smaller ticks can be seen on the time axis at 1930, 1960 and 1990).
Example: http://oxyplot.iam.at/examplesvg.aspx?title=DateTimeAxisFiala.DateTime+axis2+Fiala
Code: http://oxyplot.iam.at/examplecode.aspx?title=DateTimeAxisFiala.DateTime+axis2+Fiala

Am I missing a setting?
Thank You, Franz 

Coordinator
Feb 23, 2012 at 9:16 PM

Thanks for attaching the example, getting the code makes it much easier to reproduce the bugs!

Sorry, the DateTimeAxis is not completed yet - I see it does not work properly with long (100 years) time ranges.

I tried setting the IntervalType = DateTimeIntervalType.Years (which should force the axis to show years only). I also think that part of the problem is that MajorStep/MinorStep (in days) cannot handle leap years properly. A solution could be to give Minimum/Maximum/MajorStep/MinorStep in years when the Interval type is Years.

Workaround: Can you use a LinearAxis with years as numbers instead?

Can I include your example as a test we can use to get the "long-term" DateTimeAxis working?

Feb 24, 2012 at 3:07 PM
Edited Feb 27, 2012 at 1:29 PM

Thanks for the advice to use LinearAxes instead of DateTimeAxes. This version now works perfectly.

Example: http://oxyplot.iam.at/examplesvg.aspx?title=DateTimeAxisFiala.DateTime+axis3+Fiala
Code: http://oxyplot.iam.at/examplecode.aspx?title=DateTimeAxisFiala.DateTime+axis3+Fiala

In this example the given dates are yyyy-01-01 so the numbers forming the data series appear as integer values. I am using a conversion function to convert each DateTime value down to milliseconds into an double value considering the leapyears. May be You can use the conversion function to get a certain datetime number:

        static double DateToNumber(DateTime date)
        {
            int[] DaysToMonth = { 0, 31, 59, 90, 120, 151, 181, 212, 243, 273, 304, 334 };
            int Year = date.Year;
            bool IsLeapYear = ((Year % 4 == 0) && (Year % 100 != 0)) || (Year % 400 == 0);
            int LeapDay = IsLeapYear && (date.Month > 2) ? 1 : 0;
            long SecondsPerYear = (365+LeapDay) * 24 * 60 * 60;
            double TimeInYears = Year + (date.Millisecond*1.0/1000 + date.Second + date.Minute * 60 + date.Hour * 3600 + (date.Day-1 + LeapDay + DaysToMonth[date.Month-1]) * 3600 * 24)/SecondsPerYear;
            return TimeInYears;
        }

It works exactly up to yyyy-12-31 24:59:59.999

Some of my DateTime experiments:

Example1:http://austr.iam.at/?cmd=cat&arg=153
Example2:http://austr.iam.at/?cmd=cat&arg=86 

(You can use all of these functions.)