2012-11-28 75 views
2

我能夠做出圖表X軸DateTime格式來顯示,但我無法獲取日期的時候我的鼠標點到曲線的項目中,只有PointPair雙返回數據。我如何得到日期?如何使用C#中的ZedGraph從X軸中的PointPair獲取日期時間?

myPane.XAxis.Type = AxisType.Date; 
myPane.XAxis.Scale.Min = new XDate(DateTime.Now); // We want to use time from now 
myPane.XAxis.Scale.Max = new XDate(DateTime.Now.AddMinutes(5)); // to 5 minutes per default 
myPane.XAxis.Scale.MinorUnit = DateUnit.Second;   // set the minimum x unit to time/seconds 
myPane.XAxis.Scale.MajorUnit = DateUnit.Minute;   // set the maximum x unit to time/minutes 
myPane.XAxis.Scale.Format = "T"; 

下面是功能

private string MyPointValueHandler(ZedGraphControl control, GraphPane pane, CurveItem curve, int iPt) 
{ 
     // Get the PointPair that is under the mouse 
     PointPair pt = curve[iPt]; 

     if(curve.Label.Text == "Temperature") 
      return curve.Label.Text + " is " + pt.Y.ToString("f2") + " ºC at " + pt.X.ToString("f2"); 
     else 
      return curve.Label.Text + " is " + pt.Y.ToString("f2") + " % at " + pt.X.ToString("f2"); 

} 

我要像如結果:溫度23℃是在下午4點20分十二秒

回答

1
PointPair pt = curve[iPt]; 
    XDate the_date = new XDate(pt.X); 

    if(curve.Label.Text == "Temperature") 
     return curve.Label.Text + " is " + pt.Y.ToString("f2") + " ºC at " + the_date.DateTime; 
    else 
     return curve.Label.Text + " is " + pt.Y.ToString("f2") + " % at " + the_date.DateTime; 
+0

謝謝!有用! – hexacool

+0

歡迎您,:) –

相關問題