BUG (and BUGFIX): Interval calculation for DateTime (and Category) axes

Jul 30, 2014 at 8:24 AM
Edited Jul 30, 2014 at 8:29 AM
AxisBase.IntervalChanged contains two expressions similar to the following:

(DateTime.Now + TimeSpan.Parse(this.Interval.ToString())).ToOADate() - DateTime.Now.ToOADate()

(This may not be an exact source match; I'm going from the disassembly.)

This results in an incorrect interval being calculated, because the second DateTime.Now returns a date later than the first.

The fix is simply to assign DateTime.Now once to a local variable at the start of the method and use that in the four places where DateTime.Now is currently called.

If somebody who's working on the project could fix this, that would be great. :)

Cheers,
Simon

P.S. The obvious symptom of this is that, using DateTimeXAxis and Interval="1", and starting from midnight on some date, you see the first date twice, because the interval gets calculated at a number (very slightly) smaller than 1.
Jul 30, 2014 at 8:53 AM
UPDATE: I just uploaded a patch for this (patch 16664), so hopefully we'll see it fixed in the next release. :)

Also, if my description isn't clear enough (although I think it should be), I just spotted that someone else experienced the same thing some months back. So here's another description of what I'm pretty sure is the same problem:

https://sparrowtoolkit.codeplex.com/discussions/455474
Jul 31, 2014 at 12:29 AM
Edited Jul 31, 2014 at 12:33 AM
Until this gets fixed, here's a workaround:

1) Add an Initialized event handler, e.g.:

<sparrow:SparrowChart Initialized="TrendChart_OnInitialized">

2) Set the AxisBase.MInterval field in the callback method, something like this:
    private void TrendChart_OnInitialized(object sender, EventArgs e)
    {
        var xAxis = ((SparrowChart) sender).XAxis;

        var mIntervalField = xAxis.GetType().GetField("MInterval",
            BindingFlags.NonPublic | BindingFlags.Instance);

        if (mIntervalField != null)
        {
            mIntervalField.SetValue(xAxis, 1.0); // One day.
        }
    }