在带有图表库的C#中的WinFormsApplication中通过X和Y添加图表点的问题

时间:2019-06-18 13:49:24

标签: c# .net

我正在尝试通过X和Y坐标提取图表上的数据。

我试图将数据放在图表上,但是SQLite的服务器拒绝我,并显示以下消息:

  

System.ArgumentOutOfRangeException:'年,月和日参数描述了无法表示的DateTime。

if (comboBox1.Text == temp)
{
    string selectTemp = "SELECT Temp FROM meteodata WHERE Station= '" + comboBox2.SelectedItem.ToString() + "' AND Dat BETWEEN '" + comboBox3.SelectedItem.ToString() + "' AND '" + comboBox3.SelectedItem.ToString() + "' ORDER by Dat";

    SQLiteDataAdapter insertData = new SQLiteDataAdapter(selectTemp, Connection);
    DataTable dt = new DataTable();
    insertData.Fill(dt);
    var StartDate = comboBox3.Text;
    var EndDate = comboBox4.Text;
    int i = 0;

    chart1.Series["Temp"].Points.Clear();

    int startYear2 = 0;

    int.TryParse(StartDate, out startYear2);
    DateTime dtStart2 = new DateTime(startYear2, 01, 01);
    chart1.Series["Temp"].XValueType = ChartValueType.DateTime;
    chart1.ChartAreas[0].AxisX.LabelStyle.Format = "yyyy-MM-dd";
    chart1.ChartAreas[0].AxisX.Interval = 7;
    chart1.ChartAreas[0].AxisX.IntervalType = DateTimeIntervalType.Days;
    chart1.ChartAreas[0].AxisX.IntervalOffset = 1;

    chart1.Series["Temp"].MarkerSize = 10;
    chart1.Series["Temp"].Color = Color.Blue;
    chart1.Series["Temp"].BorderWidth = 2;

    foreach (DataRow row in dt.Rows)
    {
        chart1.Series["Temp"].Points.AddXY(dtStart2.AddDays(i), row.ItemArray[0]);
        i++;
    }
}

图片:DateTime error

0 个答案:

没有答案