gpt4 book ai didi

c# - 如何在 C# 中使用 ZedGraph 从 X 轴上的 PointPair 获取日期时间?

转载 作者:太空宇宙 更新时间:2023-11-03 13:51:20 25 4
gpt4 key购买 nike

我可以让图表的 X 轴以 DateTime 格式显示,但是当我的鼠标指向曲线项时我无法获取日期时间,PointPair 只返回 double 据。我如何获得日期?

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;

关于c# - 如何在 C# 中使用 ZedGraph 从 X 轴上的 PointPair 获取日期时间?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/13600564/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com