简体   繁体   English

Oxyplot C#DateTimeAxis在图表中显示点数据

[英]Oxyplot C# DateTimeAxis show point data in graph

if i create a DateTimeAxis with c# like this: 如果我使用c#创建一个DateTimeAxis:

        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 年份:0。#### X:6.2523

So the X-information is correct but i don't know why oxyplot doesn't show the correct year? 所以X信息是正确的,但我不知道为什么oxyplot没有显示正确的年份?

It looks like there is an issue with the series TrackerFormatString property. 看起来系列TrackerFormatString属性存在问题。 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. 有关其定义请参见氧标图文档的第44页第1.3.4节

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. 看起来它将字符串格式字符串{Date:0.###}字面上视为double,而不是使用关联属性填充它。

To get the right output, add fs.TrackerFormatString = "Year: {2:yyyy-MM-dd} X: {4:0.###}"; 要获得正确的输出,请添加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. 如果要使用标准C#DateTime格式字符串语法,可以不同地格式化日期。

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 {0}系列的标题{1} x轴的标题{2} x值{3} y轴的标题{4} y值

Note how I am using {2} and {4} above to get the x-value and y-value respectively. 请注意我如何使用上面的{2}和{4}分别获取x值和y值。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM