C#Graph Error只能设置1个Y值

时间:2015-09-28 11:00:27

标签: c# winforms charts ms-access-2010

尝试网上有关错误的代码

  

您只能为此数据点设置1个Y值。参数名称:yValue

try
{
    con.Open();
    cmd = new OleDbCommand("SELECT Sum(GrandTotal) AS SumOfGrandTotal,InvoiceDate FROM Invoice GROUP BY InvoiceDate HAVING (InvoiceDate between #" + dateTimePicker1.Value + "# and #" + dateTimePicker2.Value + "#);", con);
    OleDbDataAdapter da = new OleDbDataAdapter(cmd);
    DataSet ds = new DataSet();
    da.Fill(ds);
    DataView source = new DataView(ds.Tables[0]);
    chart1.DataSource = source;
    dr = cmd.ExecuteReader(CommandBehavior.CloseConnection);
    while (dr.Read() == true)
    {
        chart1.Series[0].Points.AddXY(dr["InvoiceDate"].ToString());//,dr["GrandTotal"].ToString());
        //chart1.Series[0].YValuesPerPoint = 2;
    }
    con.Close();
}
catch (Exception ex)
{
    MessageBox.Show(ex.Message, "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
}

我正在使用 。此代码适用于图表列。我想在数据库上获取日期并获得他们的总计。

1 个答案:

答案 0 :(得分:0)

尝试更改

chart1.Series[0].Points.AddXY(dr["InvoiceDate"].ToString());//,dr["GrandTotal"].ToString());

chart1.Series[0].Points.AddXY(dr["InvoiceDate"].ToString(), (double)dr["SumOfGrandTotal"]);