简体   繁体   English

图表以从 textbox.text 中获取用户的值并在 y 轴上绘制最大值和最小值以 hh:mm 为单位

[英]Chart to take values from user from textbox.text and plot max and min values on y-axis for time in hh:mm

Here is the screen shot..I did what you said but now when I run the code ...the x-axis scale just goes blank ...这是屏幕截图..我按照你说的做了,但是现在当我运行代码时...... x 轴刻度变成空白......

chart1.ChartAreas[0].AxisX.Minimum = Convert.ToDateTime(textBox7.Text).ToOADate();
chart1.ChartAreas[0].AxisX.Maximum = Convert.ToDateTime(textBox8.Text).ToOADate(); 

and here is the screen shot in dubugging mode, it shows some random numbers... Don't know whats that...这是在调试模式下的屏幕截图,它显示了一些随机数......不知道那是什么......

It's the same even if i do this:即使我这样做也是一样的:

chart1.ChartAreas[0].AxisX.Minimum = DateTime.Parse(textBox7.Text).ToOADate();
chart1.ChartAreas[0].AxisX.Maximum = DateTime.Parse(textBox8.Text).ToOADate(); 

在此处输入图片说明

在此处输入图片说明

previous values are as shown in the fig below..以前的值如下图所示.. 以前的价值观

these are the values from DataGridView I am displaying on chart for Time vs Temperature...and the red circle indicates the Time values, whose Min and Max values is what I want to trying to take from Textbox7.text and Textbox8.text and display on chart X-AXIS....这些是来自 DataGridView 的值,我在图表上显示时间与温度的关系......红色圆圈表示时间值,其最小值和最大值是我想要从 Textbox7.text 和 Textbox8.text 中获取并显示的值在图表 X 轴上.... 在此处输入图片说明

By default, Minimum and Maximum are waiting for doubles, and that's what you're doing here:默认情况下, MinimumMaximum正在等待双打,这就是您在这里所做的:

chart1.ChartAreas[0].AxisX.Minimum = Convert.ToDouble(textBox1.Text);

But you're trying to convert 09:27 to a double which can't be done because it's in an invalid format.但是您正在尝试将09:27转换为无法完成的双09:27 ,因为它的格式无效。

But if you want to work with time, you have to set XValueType to Time and parse your TextBox to a DateTime like so:但是,如果您想处理时间,则必须将 XValueType 设置为Time并将您的 TextBox 解析为 DateTime,如下所示:

chart1.ChartAreas[0].AxisX.Minimum = DateTime.Parse(textBox1.Text).ToOADate();

And it should do the trick.它应该可以解决问题。


Using DateTime.Parse(textBox1.Text) will create an object with today's date and the requested Time.使用DateTime.Parse(textBox1.Text)将创建一个具有今天日期和请求时间的对象。 In your case, you're interested in keeping the date ( 08/30/2016 ).就您而言,您有兴趣保留日期 ( 08/30/2016 )。 What you have to do is:你需要做的是:

// Get the old date
DateTime currentDateMin = DateTime.FromOADate(chart1.ChartAreas[0].AxisX.Minimum);
// Parse the date you want to set
DateTime requestesd = DateTime.Parse(textBox1.Text);
// Set the time part
DateTime newDateMin = new DateTime(currentDateMin.Year, currentDateMin.Month, currentDateMin.Day, requestesd.Hour, requestesd.Minute, requestesd.Second);
// Assign to your axis
chart1.ChartAreas[0].AxisX.Minimum = newDateTime.ToOADate();

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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