简体   繁体   中英

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

I able to make the graph X axis to display in DateTime format, but I couldn't to get date time when my mouse point to the curve item, the PointPair only return data in double. How do I get the date ?

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";

Below is the function

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");

}

I want to the result like eg: Temperature is 23ºC at 4:20:12 pm

    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;

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM