尝试网上有关错误的代码
您只能为此数据点设置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);
}
答案 0 :(得分:0)
尝试更改
chart1.Series[0].Points.AddXY(dr["InvoiceDate"].ToString());//,dr["GrandTotal"].ToString());
要
chart1.Series[0].Points.AddXY(dr["InvoiceDate"].ToString(), (double)dr["SumOfGrandTotal"]);