繁体   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