5

if i create a DateTimeAxis with c# like this:

        DateTimeAxis xAxis = new DateTimeAxis
        {
            Position = AxisPosition.Bottom,
            StringFormat = "dd/MM/yyyy",

            Title = "Year",
            MinorIntervalType = DateTimeIntervalType.Days,
            IntervalType = DateTimeIntervalType.Days,
            MajorGridlineStyle = LineStyle.Solid,
            MinorGridlineStyle = LineStyle.None,
        };

        FunctionSeries fs = new FunctionSeries();
        fs.Points.Add(new DataPoint(DateTimeAxis.ToDouble(DateTime.Now), 5));
        fs.Points.Add(new DataPoint(DateTimeAxis.ToDouble(new DateTime(1989, 10, 3)), 8));

        PlotModel n = new PlotModel();
        n.Series.Add(fs);
        n.Axes.Add(xAxis);
        n.Axes.Add(new LinearAxis());

        pv.Model = n;

Everything is drawing fine on the graph but if i press on the point i get this data as label:

Year: 0.#### X: 6.2523

So the X-information is correct but i don't know why oxyplot doesn't show the correct year?

binaryBigInt
  • 1,526
  • 2
  • 18
  • 44

1 Answers1

4

It looks like there is an issue with the series TrackerFormatString property. Which is used to format the string shown when you click on the graph.

See page 44, section 1.3.4 of the oxyplot documentation for its definition.

It looks like it is treating the string format string {Date:0.###} literally as a double instead of filling it in with the associated property.

To get the right output, add fs.TrackerFormatString = "Year: {2:yyyy-MM-dd} X: {4:0.###}"; to your code. You can format the date differentely if you would like using the standard C# DateTime format string syntax.

This thread, was particularly helpful in figuring out the un-documented settings. In particular the following is relevant,

The tracker format string has some variations for different series (should be documented... and maybe improved?), but it should at least support the following arguments

{0} the title of the series {1} the title of the x-axis {2} the x-value {3} the title of the y-axis {4} the y-value

Note how I am using {2} and {4} above to get the x-value and y-value respectively.

Community
  • 1
  • 1
William Denman
  • 3,046
  • 32
  • 34
  • 1
    Thanks for your answer, i added the rest of my code to the original post. I don't see any information on the document you linked which could help me, because of "This section is under construction". – binaryBigInt Oct 01 '15 at 20:04
  • 1
    Ok, I can re-create your error now. I'm on the case. – William Denman Oct 01 '15 at 20:18
  • 1
    Thanks man! If i add your code line everything works just fine! I really appreciate your help :) Have a nice weekend – binaryBigInt Oct 02 '15 at 13:05
  • @WilliamDenman Does TrackerFormatString work with Xamarin forms? – LCJ Aug 04 '17 at 21:40