Search code examples
c#wpfoxyplot

Irregular interval on DateTime Axis in OxyPlot


I have a WPF application in which I am using OxyPlot for charting. I add points continuously to the lineseries in the chart. The X-Axis is a DateTime axis whose interval type is set to seconds. Points are added continuously to the line series. When the timespan between first and last point is a particular number of seconds, I remove the first point and Invalidate the plot. This makes the X-Axis scroll. I have noticed that the Interval is not regular though. The interval changes sometimes. See the following images:

enter image description here

This is the interval when the chart starts plotting.

After a while the interval is like this:

enter image description here

How do I make the interval fixed that is as in the first image?


Solution

  • You need to set the properties of the x-axis object.

    e.g. below I'm creating and x-axis which represents the 'End of Day' where the interval is a Day and the minimum interval is also a day, this prevent it trying to show half or quarter days when I zoom into the plot.

    _xAxis = new DateTimeAxis
    {
        Position = AxisPosition.Bottom,
        StringFormat = Constants.MarketData.DisplayDateFormat,
        Title = "End of Day",
        IntervalLength = 75,
        MinorIntervalType = DateTimeIntervalType.Days,
        IntervalType = DateTimeIntervalType.Days,
        MajorGridlineStyle = LineStyle.Solid,
        MinorGridlineStyle = LineStyle.None,
    };