Oxyplot没有显示时间轴

时间:2015-10-16 14:05:35

标签: c# plot diagram milliseconds oxyplot

我想用毫秒绘制时间轴上的数据值。 这是我的方法:

myModel = new PlotModel();

myModel.Axes.Add(new LinearAxis());
myModel.Axes.Add(new DateTimeAxis()
{
    Position = AxisPosition.Bottom,
    StringFormat = "HH:mm:ss",
    IntervalLength = 60,
    MinorIntervalType = DateTimeIntervalType.Milliseconds,
    IntervalType = DateTimeIntervalType.Milliseconds,
    MajorGridlineStyle = LineStyle.Solid,
    MinorGridlineStyle = LineStyle.Solid,
});

var cs = new LineSeries();
for (int i = 1; i < 10; i++) //generate test values
{
    var dp = new DataPoint()
    {
        X = DateTimeAxis.ToDouble(DateTime.ParseExact("14:02:02.0" + Convert.ToString(i + 9), "HH:mm:ss.fff", System.Globalization.CultureInfo.InvariantCulture)),
        Y = i * i
    };
    cs.Points.Add(dp);
}

myModel.Series.Add(cs);

问题是图表没有显示x轴上的值: Graph

如果我不解析毫秒,那么一切都会正确显示:

DateTimeAxis.ToDouble(DateTime.ParseExact("14:02:" + Convert.ToString(i + 9), "HH:mm:ss", System.Globalization.CultureInfo.InvariantCulture))

时间被正确解析,但Oxyplot无法以某种方式解决它。

1 个答案:

答案 0 :(得分:0)

首先猜测:当您更改解析日期时,由于您的for循环以及您追加时间的方式,您的值突然在毫秒范围内。 e.g。

"14:02: + Convert.ToString(i+9)" gives you 14:02:10 through 14:02:18

"14:02:02.0 + Convert.ToString(i+9)" gives you 14:02:02.10 through 14:02:02.18

给出DateTimeAxis的格式字符串

StringFormat = "HH:mm:ss" 

它无法显示毫秒分辨率,因此您什么也看不见。将字符串格式(或不指定)更改为:

StringFormat = "HH:mm:ss.fff" 

或者指定一个标签格式化程序,以选择性地以毫秒级分辨率显示,类似于这个问题:OxyPlot. How to change Format of values next to the axis from 1000 to 1k

相关问题