使用多个过滤器填充 winform 图表
Posted
技术标签:
【中文标题】使用多个过滤器填充 winform 图表【英文标题】:Populate winform chart with multiple filters 【发布时间】:2021-05-18 06:28:02 【问题描述】:在我的 winform 应用程序中,我想填充我的图表,其中数据源是具有多个参数的存储过程,参数的值将从 winform 控件提供。 但是当我点击过滤器按钮时,只有日期标准得到评估,而其他所有标准都没有,请验证我下面的图像和代码,并请指导我哪里错了:
我的winform图片:
图表数据代码:
ArrayList deptname = new ArrayList();
ArrayList deptcount = new ArrayList();
ArrayList deptname2 = new ArrayList();
ArrayList deptsum2 = new ArrayList();
ArrayList rejcat = new ArrayList();
ArrayList rejsum = new ArrayList();
private void btnfilter_Click(object sender, EventArgs e)
deptname.Clear();
deptcount.Clear();
deptpercentage();
deptname2.Clear();
deptsum2.Clear();
deptrejqty();
rejcat.Clear();
rejsum.Clear();
toprejreason();
private void toprejreason()
SqlConnection con = new SqlConnection(cs);
SqlCommand cmd = new SqlCommand("toprejreason", con);
cmd.Parameters.AddWithValue("@fromDate", dtfrom.Value);
cmd.Parameters.AddWithValue("@toDate", dtto.Value);
cmd.Parameters.AddWithValue("@depname", comboBox1.Text);
cmd.Parameters.AddWithValue("@mattype", textBox1.Text);
cmd.Parameters.AddWithValue("@matnum", textBox2.Text);
cmd.CommandType = CommandType.StoredProcedure;
con.Open();
SqlDataReader dr = cmd.ExecuteReader();
while (dr.Read())
rejcat.Add(dr.GetString(0));
rejsum.Add(dr.GetInt32(1));
chart1.Series[0].Points.DataBindXY(rejcat, rejsum);
dr.Close();
con.Close();
private void deptrejqty()
SqlConnection con = new SqlConnection(cs);
SqlCommand cmd = new SqlCommand("deptrejqty", con);
cmd.Parameters.AddWithValue("@fromDate", dtfrom.Value);
cmd.Parameters.AddWithValue("@toDate", dtto.Value);
cmd.Parameters.AddWithValue("@depname", comboBox1.Text);
cmd.Parameters.AddWithValue("@mattype", textBox1.Text);
cmd.Parameters.AddWithValue("@matnum", textBox2.Text);
cmd.CommandType = CommandType.StoredProcedure;
con.Open();
SqlDataReader dr = cmd.ExecuteReader();
while (dr.Read())
deptname2.Add(dr.GetString(0));
deptsum2.Add(dr.GetDecimal(1));
deptrej.Series[0].Points.DataBindXY(deptname2, deptsum2);
dr.Close();
con.Close();
private void deptpercentage()
SqlConnection con = new SqlConnection(cs);
SqlCommand cmd = new SqlCommand("deptpercentage", con);
cmd.Parameters.AddWithValue("@fromDate", dtfrom.Value);
cmd.Parameters.AddWithValue("@toDate", dtto.Value);
cmd.Parameters.AddWithValue("@depname", comboBox1.Text);
cmd.Parameters.AddWithValue("@mattype", textBox1.Text);
cmd.Parameters.AddWithValue("@matnum", textBox2.Text);
cmd.CommandType = CommandType.StoredProcedure;
con.Open();
SqlDataReader dr = cmd.ExecuteReader();
while (dr.Read())
deptname.Add(dr.GetString(0));
deptcount.Add(dr.GetDecimal(1));
chartdeptper.Series[0].Points.DataBindXY(deptname, deptcount);
dr.Close();
con.Close();
private void FormDashboard_FormClosed(object sender, FormClosedEventArgs e)
Application.Exit();
存储过程代码:
create proc toprejreason
@fromDate Date,
@toDate Date,
@depname varchar,
@mattype varchar,
@matnum varchar
as
select top 10 Reason_Brief as Reason, Sum(Rejection_Qty) as Quantity
from Semicon_NPD
Where Date between @fromDate and @toDate or Department=@depname or Material_Type=@mattype or Material_Number=@matnum
group by Reason_Brief
order by Sum(Rejection_Qty) desc
go
新程序:
@fromDate Date,
@toDate Date,
@depname varchar(50),
@mattype varchar(50),
@matnum varchar(50)
as
select top 10 Reason_Brief as Reason, Sum(Rejection_Qty) as Quantity
from Semicon_NPD
Where Date between @fromDate and @toDate or Department=@depname or Material_Type=@mattype or Material_Number=@matnum
group by Reason_Brief
order by Sum(Rejection_Qty) desc
<body>
<!--[if !excel]> <![endif]-->
<!--The following information was generated by Microsoft Excel's Publish as Web
Page wizard.-->
<!--If the same item is republished from Excel, all information between the DIV
tags will be replaced.-->
<!----------------------------->
<!--START OF OUTPUT FROM EXCEL PUBLISH AS WEB PAGE WIZARD -->
<!----------------------------->
<div id="Book1_2966" align="center" x:publishsource="Excel">
<table border="0" cellpadding="0" cellspacing="0" style="border-collapse:
collapse;table-layout:fixed;width:1662pt">
<colgroup><col style="mso-width-source:userset;mso-width-alt:731;width:15pt">
<col style="mso-width-source:userset;mso-width-alt:2669;width:55pt">
<col style="mso-width-source:userset;mso-width-alt:1280;width:26pt">
<col style="mso-width-source:userset;mso-width-alt:4315;width:89pt">
<col style="mso-width-source:userset;mso-width-alt:3547;width:73pt">
<col style="mso-width-source:userset;mso-width-alt:3437;width:71pt">
<col style="mso-width-source:userset;mso-width-alt:3730;width:77pt">
<col style="mso-width-source:userset;mso-width-alt:2633;width:54pt">
<col style="mso-width-source:userset;mso-width-alt:3510;width:72pt">
<col style="mso-width-source:userset;mso-width-alt:2998;width:62pt">
<col style="mso-width-source:userset;mso-width-alt:4278;width:88pt">
<col style="mso-width-source:userset;mso-width-alt:12507;width:257pt">
<col span="4" style="mso-width-source:userset;mso-width-alt:4022;
width:83pt">
<col style="mso-width-source:userset;mso-width-alt:12288;width:252pt">
<col style="mso-width-source:userset;mso-width-alt:3364;width:69pt">
<col style="mso-width-source:userset;mso-width-alt:3401;width:70pt">
</colgroup><tbody><tr style="height:15.0pt">
<td class="xl652966" style="height:15.0pt;width:15pt">ID</td>
<td class="xl652966" style="border-left:none;width:55pt">Date</td>
<td class="xl652966" style="border-left:none;width:26pt">MRP</td>
<td class="xl652966" style="border-left:none;width:89pt">Material_Number</td>
<td class="xl652966" style="border-left:none;width:73pt">Material_Type</td>
<td class="xl652966" style="border-left:none;width:71pt">Weight_in_Kg</td>
<td class="xl652966" style="border-left:none;width:77pt">Order_Number</td>
<td class="xl652966" style="border-left:none;width:54pt">Order_Qty</td>
<td class="xl652966" style="border-left:none;width:72pt">Rejection_Qty</td>
<td class="xl652966" style="border-left:none;width:62pt">Department</td>
<td class="xl652966" style="border-left:none;width:88pt">Reason_Brief</td>
<td class="xl652966" style="border-left:none;width:257pt">Reason_Explained</td>
<td class="xl652966" style="border-left:none;width:83pt">Responsibility_1</td>
<td class="xl652966" style="border-left:none;width:83pt">Responsibility_2</td>
<td class="xl652966" style="border-left:none;width:83pt">Responsibility_3</td>
<td class="xl652966" style="border-left:none;width:83pt">Responsibility_4</td>
<td class="xl652966" style="border-left:none;width:252pt">Corrective_Action</td>
<td class="xl652966" style="border-left:none;width:69pt">Action_Taken</td>
<td class="xl652966" style="border-left:none;width:70pt">Action_Status</td>
</tr>
<tr style="height:15.0pt">
<td class="xl632966" align="right" style="height:15.0pt;border-top:
none">1</td>
<td class="xl642966" align="right" style="border-top:none;border-left:none">13-02-2021</td>
<td class="xl632966" align="right" style="border-top:none;border-left:none">1</td>
<td class="xl632966" align="right" style="border-top:none;border-left:none">1137</td>
<td class="xl632966" style="border-top:none;border-left:none">A</td>
<td class="xl632966" align="right" style="border-top:none;border-left:none">0.233</td>
<td class="xl632966" align="right" style="border-top:none;border-left:none">12345</td>
<td class="xl632966" align="right" style="border-top:none;border-left:none">336</td>
<td class="xl632966" align="right" style="border-top:none;border-left:none">2</td>
<td class="xl632966" style="border-top:none;border-left:none">Milling</td>
<td class="xl632966" style="border-top:none;border-left:none">Surface Defect</td>
<td class="xl632966" style="border-top:none;border-left:none">Ahite paches
appear on surface</td>
<td class="xl632966" style="border-top:none;border-left:none">Grinding</td>
<td class="xl632966" style="border-top:none;border-left:none">NULL</td>
<td class="xl632966" style="border-top:none;border-left:none">NULL</td>
<td class="xl632966" style="border-top:none;border-left:none">NULL</td>
<td class="xl632966" style="border-top:none;border-left:none">Common Problem,
Analysis to be requeired</td>
<td class="xl632966" style="border-top:none;border-left:none">NULL</td>
<td class="xl632966" style="border-top:none;border-left:none">Pending</td>
</tr>
<tr style="height:15.0pt">
<td class="xl632966" align="right" style="height:15.0pt;border-top:
none">2</td>
<td class="xl642966" align="right" style="border-top:none;border-left:none">13-02-2021</td>
<td class="xl632966" align="right" style="border-top:none;border-left:none">1</td>
<td class="xl632966" align="right" style="border-top:none;border-left:none">1137</td>
<td class="xl632966" style="border-top:none;border-left:none">A</td>
<td class="xl632966" align="right" style="border-top:none;border-left:none">0.272</td>
<td class="xl632966" align="right" style="border-top:none;border-left:none">12345</td>
<td class="xl632966" align="right" style="border-top:none;border-left:none">30</td>
<td class="xl632966" align="right" style="border-top:none;border-left:none">1</td>
<td class="xl632966" style="border-top:none;border-left:none">Milling</td>
<td class="xl632966" style="border-top:none;border-left:none">Surface Defect</td>
<td class="xl632966" style="border-top:none;border-left:none">Unclear appear on
3.1mm slot after milling operation</td>
<td class="xl632966" style="border-top:none;border-left:none">NPD</td>
<td class="xl632966" style="border-top:none;border-left:none">NULL</td>
<td class="xl632966" style="border-top:none;border-left:none">NULL</td>
<td class="xl632966" style="border-top:none;border-left:none">NULL</td>
<td class="xl632966" style="border-top:none;border-left:none">Common Problem,
Analysis to be done</td>
<td class="xl632966" style="border-top:none;border-left:none"> </td>
<td class="xl632966" style="border-top:none;border-left:none">Pending</td>
</tr>
<tr style="height:15.0pt">
<td class="xl632966" align="right" style="height:15.0pt;border-top:
none">3</td>
<td class="xl642966" align="right" style="border-top:none;border-left:none">14-02-2021</td>
<td class="xl632966" align="right" style="border-top:none;border-left:none">101</td>
<td class="xl632966" align="right" style="border-top:none;border-left:none">1137</td>
<td class="xl632966" style="border-top:none;border-left:none">A</td>
<td class="xl632966" align="right" style="border-top:none;border-left:none">0.093</td>
<td class="xl632966" align="right" style="border-top:none;border-left:none">12345</td>
<td class="xl632966" align="right" style="border-top:none;border-left:none">12</td>
<td class="xl632966" align="right" style="border-top:none;border-left:none">3</td>
<td class="xl632966" style="border-top:none;border-left:none">Turning</td>
<td class="xl632966" style="border-top:none;border-left:none">Chipping</td>
<td class="xl632966" style="border-top:none;border-left:none">small chippoff on
edge</td>
<td class="xl632966" style="border-top:none;border-left:none">Process</td>
<td class="xl632966" style="border-top:none;border-left:none">NULL</td>
<td class="xl632966" style="border-top:none;border-left:none">NULL</td>
<td class="xl632966" style="border-top:none;border-left:none">NULL</td>
<td class="xl632966" style="border-top:none;border-left:none">From Next Bacth
order Aill take care of this problem</td>
<td class="xl632966" style="border-top:none;border-left:none">NULL</td>
<td class="xl632966" style="border-top:none;border-left:none">Pending</td>
</tr>
<tr style="height:15.0pt">
<td class="xl632966" align="right" style="height:15.0pt;border-top:
none">4</td>
<td class="xl642966" align="right" style="border-top:none;border-left:none">15-02-2021</td>
<td class="xl632966" align="right" style="border-top:none;border-left:none">1</td>
<td class="xl632966" align="right" style="border-top:none;border-left:none">1137</td>
<td class="xl632966" style="border-top:none;border-left:none">AL10</td>
<td class="xl632966" align="right" style="border-top:none;border-left:none">0.079</td>
<td class="xl632966" align="right" style="border-top:none;border-left:none">12345</td>
<td class="xl632966" align="right" style="border-top:none;border-left:none">12</td>
<td class="xl632966" align="right" style="border-top:none;border-left:none">1</td>
<td class="xl632966" style="border-top:none;border-left:none">EDM</td>
<td class="xl632966" style="border-top:none;border-left:none">Out of Dimension</td>
<td class="xl632966" style="border-top:none;border-left:none">Side slot -0.02
minimum side comes in milling</td>
<td class="xl632966" style="border-top:none;border-left:none">Operators</td>
<td class="xl632966" style="border-top:none;border-left:none">NULL</td>
<td class="xl632966" style="border-top:none;border-left:none">NULL</td>
<td class="xl632966" style="border-top:none;border-left:none">NULL</td>
<td class="xl632966" style="border-top:none;border-left:none">No</td>
<td class="xl632966" style="border-top:none;border-left:none">NULL</td>
<td class="xl632966" style="border-top:none;border-left:none">Not required</td>
</tr>
<tr style="height:15.0pt">
<td class="xl632966" align="right" style="height:15.0pt;border-top:
none">5</td>
<td class="xl642966" align="right" style="border-top:none;border-left:none">15-02-2021</td>
<td class="xl632966" align="right" style="border-top:none;border-left:none">101</td>
<td class="xl632966" align="right" style="border-top:none;border-left:none">1137</td>
<td class="xl632966" style="border-top:none;border-left:none">TZM</td>
<td class="xl632966" align="right" style="border-top:none;border-left:none">0.083</td>
<td class="xl632966" align="right" style="border-top:none;border-left:none">12345</td>
<td class="xl632966" align="right" style="border-top:none;border-left:none">63</td>
<td class="xl632966" align="right" style="border-top:none;border-left:none">1</td>
<td class="xl632966" style="border-top:none;border-left:none">EDM</td>
<td class="xl632966" style="border-top:none;border-left:none">Chipping</td>
<td class="xl632966" style="border-top:none;border-left:none">small chippoff on
edge</td>
<td class="xl632966" style="border-top:none;border-left:none">Grinding</td>
<td class="xl632966" style="border-top:none;border-left:none">NULL</td>
<td class="xl632966" style="border-top:none;border-left:none">NULL</td>
<td class="xl632966" style="border-top:none;border-left:none">NULL</td>
<td class="xl632966" style="border-top:none;border-left:none">Setters should be
take care of this problem</td>
<td class="xl632966" style="border-top:none;border-left:none">NULL</td>
<td class="xl632966" style="border-top:none;border-left:none">Completed</td>
</tr>
<tr style="height:15.0pt">
<td class="xl632966" align="right" style="height:15.0pt;border-top:
none">9</td>
<td class="xl642966" align="right" style="border-top:none;border-left:none">15-02-2021</td>
<td class="xl632966" align="right" style="border-top:none;border-left:none">1</td>
<td class="xl632966" align="right" style="border-top:none;border-left:none">1137</td>
<td class="xl632966" style="border-top:none;border-left:none">A</td>
<td class="xl632966" align="right" style="border-top:none;border-left:none">0.083</td>
<td class="xl632966" align="right" style="border-top:none;border-left:none">12345</td>
<td class="xl632966" align="right" style="border-top:none;border-left:none">63</td>
<td class="xl632966" align="right" style="border-top:none;border-left:none">1</td>
<td class="xl632966" style="border-top:none;border-left:none">Milling</td>
<td class="xl632966" style="border-top:none;border-left:none">Chipping</td>
<td class="xl632966" style="border-top:none;border-left:none">small chipoff</td>
<td class="xl632966" style="border-top:none;border-left:none">Grinding</td>
<td class="xl632966" style="border-top:none;border-left:none">NULL</td>
<td class="xl632966" style="border-top:none;border-left:none">NULL</td>
<td class="xl632966" style="border-top:none;border-left:none">NULL</td>
<td class="xl632966" style="border-top:none;border-left:none">No</td>
<td class="xl632966" style="border-top:none;border-left:none">NULL</td>
<td class="xl632966" style="border-top:none;border-left:none">Not required</td>
</tr>
<!--[if supportMisalignedColumns]-->
<tr style="display:none">
<td style="width:15pt"></td>
<td style="width:55pt"></td>
<td style="width:26pt"></td>
<td style="width:89pt"></td>
<td style="width:73pt"></td>
<td style="width:71pt"></td>
<td style="width:77pt"></td>
<td style="width:54pt"></td>
<td style="width:72pt"></td>
<td style="width:62pt"></td>
<td style="width:88pt"></td>
<td style="width:257pt"></td>
<td style="width:83pt"></td>
<td style="width:83pt"></td>
<td style="width:83pt"></td>
<td style="width:83pt"></td>
<td style="width:252pt"></td>
<td style="width:69pt"></td>
<td style="width:70pt"></td>
</tr>
<!--[endif]-->
</tbody></table>
</div>
<!----------------------------->
<!--END OF OUTPUT FROM EXCEL PUBLISH AS WEB PAGE WIZARD-->
<!----------------------------->
</body>
【问题讨论】:
Can we stop using AddWithValue() already?It's evil. Bad Habits to Kick : Declaring VARCHAR without (length);投票以印刷方式结束。 @Larnu 感谢您的链接,我在将长度分配给 varchar 并更改 add with value 以添加 sqldb 数据类型后尝试了,但问题仍然存在...... 好的,您现在需要花时间为我们发布minimal reproducible example,以便我们可以复制问题。 DDL 和 DML 中的示例数据将为您提供帮助。 不,不这样做;我没有从 Google Drive 下载一个完全陌生的文件。将信息放在问题所属的位置。 【参考方案1】:感谢您的所有回复..我使它与以下代码一起工作:
@fromDate Date,
@toDate Date,
@depname varchar(50),
@mattype varchar(50),
@matnum varchar(50)
as
select top 10 Reason_Brief as Reason, Sum(Rejection_Qty) as Quantity
from Semicon_NPD
Where (Date between @fromDate and @toDate) and (Material_Type = IIF(ISNULL(@mattype, '') = '', Material_Type, @mattype)) and (Material_Number = IIF(ISNULL(@matnum, '') = '', Material_Number, @matnum)) and (Department = IIF(ISNULL(@depname, '') = '', Department, @depname))
group by Reason_Brief
order by Sum(Rejection_Qty) desc
go
【讨论】:
以上是关于使用多个过滤器填充 winform 图表的主要内容,如果未能解决你的问题,请参考以下文章
Google图表:在图表中设置精确的日期边界(使用过滤器滑块时)