1

Presently my data is displayed in a LineSeries with both axes numeric. The X value of each point is a very small time interval. I need to display this value in a custom way. I'd like to avoid using a DateTimeAxis for the data if possible. Can I format the LinearAxis in a particular way?

Community
  • 1
  • 1
Daniel
  • 10,864
  • 22
  • 84
  • 115

1 Answers1

1

This seems to work for me. I hope I'm not misinterpreting something here, answer feels too simple.

//Start point of the data (arbitrary in this example)
var startOfData = DateTime.Now.Subtract(TimeSpan.FromDays(1));

//https://msdn.microsoft.com/en-us/library/8kb3ddd4(v=vs.110).aspx
var formatString = "m.ss.fffff";

Func<double, string> labelFormatter = 
    milliseconds => 
        startOfData
            .Add(TimeSpan.FromMilliseconds(milliseconds))
            .ToString(formatString);

Example Usage:

var pm = new PlotModel();
pm.Axes.Add(new OxyPlot.Axes.LinearAxis { Position = AxisPosition.Left });
pm.Axes.Add(new OxyPlot.Axes.LinearAxis { Position = AxisPosition.Bottom, LabelFormatter = labelFormatter });

Random random = new Random(Guid.NewGuid().GetHashCode());

var datapoints = 
    Enumerable.Range(1, 100)
        .Select(milliseconds => new DataPoint(milliseconds, random.Next(0, 10)));

var lineSeries = new OxyPlot.Series.LineSeries();
lineSeries.Points.AddRange(datapoints);

pm.Series.Add(lineSeries);

Show(pm);

Complete working linqpad script here https://github.com/kennethito/StackOverflowReferences/blob/master/Oxyplot-CustomAxis/oxyplot.linq

enter image description here

Kenneth Ito
  • 5,201
  • 2
  • 25
  • 44
  • Thanks Kenneth. I trust your solution will work, but I have not had a chance to validate yet. I will do so shortly (12-24 hours, god willing) and update. – Daniel Apr 03 '16 at 05:35