2015-10-16 300 views
1

我想以毫秒为单位在时间轴上绘制数据值。 这是我的方法: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以某种方式无法应付它。

回答

0

第一次猜测:当您更改日期时间时,解析您的值突然在毫秒范围内,因为您的for循环以及您追加的时间方式。例如

"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

+0

关于http://stackoverflow.com/review /建议编辑/ 9922180,不要这样做。相反,请发布您自己的答案。 – Deduplicator