簡體   English   中英

如何在C#中使用ZedGraph從X軸的PointPair獲取日期時間?

[英]How to get date time from PointPair in X axis using ZedGraph in C#?

我能夠使圖形X軸以DateTime格式顯示,但是當鼠標指向曲線項時,我無法獲取日期時間,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");

}

我想要這樣的結果,例如:下午4:20:12溫度為23ºC

    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;

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM