Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Oxyplot C# DateTimeAxis show point data in graph

Tags:

c#

oxyplot

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?

like image 972
binaryBigInt Avatar asked Sep 27 '22 14:09

binaryBigInt


1 Answers

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.

like image 50
William Denman Avatar answered Sep 30 '22 07:09

William Denman