How to plot DateTime v Value

May 26, 2014 at 8:20 PM
I'm sorry if this is a duplicate. I am struggling to create a plot given a list of Times and Values. The examples have the times in double format, which I'm not sure where that is coming from. Thanks for your help!
May 27, 2014 at 4:56 PM
Edited May 27, 2014 at 4:58 PM
Hello, Here is a small example. The principle is to convert the date in double with the static function DateTimeAxis.ToDouble
// Objet (client) with DateTime and double
var objList = new List<Tuple<DateTime, double>>()
 {
     new Tuple<DateTime, double>(DateTime.Now, 10),
     new Tuple<DateTime, double>(DateTime.Now.AddMonths(-1), 20),
     new Tuple<DateTime, double>(DateTime.Now.AddMonths(-2), 30),
     new Tuple<DateTime, double>(DateTime.Now.AddMonths(-3), 40),
     new Tuple<DateTime, double>(DateTime.Now.AddMonths(-4), 50),
     new Tuple<DateTime, double>(DateTime.Now.AddMonths(-5), 60)
 };

// define an axis Date  
var dateTimeAxis = new DateTimeAxis()
 {
    Title = "Date",
    Position = AxisPosition.Bottom,
    IntervalType = DateTimeIntervalType.Months,
    StringFormat = "MMM yy"
 };

// Convert object client  to  DataPoint
var points = objList.Select(obj => new DataPoint(DateTimeAxis.ToDouble(obj.Item1), obj.Item2)).ToList();

// Create Line
var linearSeries = new LineSeries("DateLine")
 {
     ItemsSource = points
 };
Marked as answer by jessimb on 5/27/2014 at 4:10 PM