我有以下代码创建一个包含三个系列的图表,第一个系列是柱形栏,第二个和第三行。当有从返回的数据时创建图表,但当没有sqlcommand
返回行时,它应该至少显示 x 和 y 轴。
C#代码:
string DatabaseConnectionString = System.Configuration.ConfigurationManager.ConnectionStrings["AVISConnectionString"].ConnectionString;
SqlConnection conn = new SqlConnection(DatabaseConnectionString);
conn.Open();
DataTable dtSr = new DataTable();
SqlCommand cmd = null;
SqlDataReader reader = null;
cmd = new SqlCommand("Select case when KWmittel is null then '0' else KWmittel end as [KWmittel], case when YTD is null then '0' else YTD end as [YTD], case when soll is null then '0' else soll end as [soll] from dbo.Ausbringung_Wiegen_2013 a inner join dbo.ytd y on a.weekID = y.weekID inner join dbo.sollno s on y.weekID = s.weekID where a.weekID < datepart(week,getdate())", conn);
reader = cmd.ExecuteReader();
if (!reader.Read())
{
//I don't know how to handle here, I just gave a try but doesn't work
Chart4.ChartAreas["Chartarea1"].AxisX.Minimum = 0;
Chart4.ChartAreas["Chartarea1"].AxisY.Minimum = 0;
Chart4.Series["s1"].YValueMembers = null;
Chart4.Series["s2"].YValueMembers = null;
Chart4.Series["s3"].YValueMembers = null;
}
dtSr.Load(reader);
Chart4.DataSource = dtSr;
Chart4.Series["s1"].YValueMembers = "KWmittel";
Chart4.Series["s2"].YValueMembers = "YTD";
Chart4.Series["s3"].YValueMembers = "soll";
Chart4.DataBind();
cmd = null;
dtSr.Clear();
我真的很感激任何帮助和想法。谢谢 :)