如何在visual studio c#中显示正确的记录数量(How to display the correct amount of records for a chart in visual stu

编程入门 行业动态 更新时间:2024-10-10 11:30:50
如何在visual studio c#中显示正确的记录数量(How to display the correct amount of records for a chart in visual studios c#)

你好所有只是一个更新,我仍然面临让图表显示正确的记录数的问题。 我已经发现了图表当前从哪里得到它的数字,然而它为什么使用这些数字毫无意义。 它来自数据库中名为“mpm_code”的列,但我从未指定图表使用这些数字。 以下是数据库中的数字:

这是图表

这是我的代码:

using System; using System.Collections.Generic; using System.ComponentModel; using System.Data; using System.Drawing; using System.Linq; using System.Text; using System.Threading.Tasks; using System.Windows.Forms; using System.Data.OleDb; namespace RRAS { public partial class formRRAS : Form { public OleDbConnection DataConnection = new OleDbConnection(); string cmbRFR_item; public formRRAS() { InitializeComponent(); } //When the form loads it sets the intial combo box RFR item to null private void formRRAS_Load(object sender, EventArgs e) { // TODO: This line of code loads data into the 'database1DataSet.tblReject_test' table. You can move, or remove it, as needed. this.tblReject_testTableAdapter.Fill(this.database1DataSet.tblReject_test); cmbRFR.SelectedItem = ""; this.AcceptButton = btnSearch; } //AddRFR method, called in the NewRFRPopup public void AddRFR(object item) { cmbRFR.Items.Add(item); } private void change_cmbSubRFR_items() { cmbSubRFR.Items.Clear();//Clear all items in cmbSubRFR comboBox. switch (cmbRFR_item)//Adding your new items to cmbSubRFR. { case "": cmbSubRFR.Items.Add(""); cmbSubRFR.Text = ""; break; case "POSITIONING": cmbSubRFR.Items.Add(""); cmbSubRFR.Items.Add("Anatomy cut-off"); cmbSubRFR.Items.Add("Rotation"); cmbSubRFR.Items.Add("Obstructed view"); cmbSubRFR.Items.Add("Tube or grid centering"); cmbSubRFR.Items.Add("Motion"); cmbSubRFR.Text = ""; break; case "ARTEFACT": cmbSubRFR.Items.Add(""); cmbSubRFR.Items.Add("ARTEFACT"); cmbSubRFR.Text = "ARTEFACT"; cmbSubRFR.Text = ""; break; case "PATIENT ID": cmbSubRFR.Items.Add(""); cmbSubRFR.Items.Add("Incorrect Patient"); cmbSubRFR.Items.Add("Incorrect Study/Side"); cmbSubRFR.Items.Add("User Defined Error"); cmbSubRFR.Text = ""; break; case "EXPOSURE ERROR": cmbSubRFR.Items.Add(""); cmbSubRFR.Items.Add("Under Exposure"); cmbSubRFR.Items.Add("Over Exposure"); cmbSubRFR.Items.Add("Exposure Malfunction"); cmbSubRFR.Text = ""; break; case "TEST IMAGES": cmbSubRFR.Items.Add(""); cmbSubRFR.Items.Add("Quality Control"); cmbSubRFR.Items.Add("Service/Test"); cmbSubRFR.Text = ""; break; } } private void cmbRFR_SelectedIndexChanged(object sender, EventArgs e) { if (cmbRFR_item != cmbRFR.SelectedItem.ToString())//This controls the changes in cmbRFR about selected item and call change_cmbSubRFR_items() { cmbRFR_item = cmbRFR.SelectedItem.ToString(); change_cmbSubRFR_items(); } } //The code for the button that closes the application private void btnSearch_Click(object sender, EventArgs e) { //This creates the String Publisher which grabs the information from the combo box on the form. //Select and Dataconnection are also defined here. string Department = String.IsNullOrEmpty(txtDepartment.Text) ? "%" : txtDepartment.Text; string Start_Date = String.IsNullOrEmpty(txtStart.Text) ? "%" : txtStart.Text; string End_Date = String.IsNullOrEmpty(txtEnd.Text) ? "%" : txtEnd.Text; string Anatomy = String.IsNullOrEmpty(txtAnatomy.Text) ? "%" : txtAnatomy.Text; string RFR = String.IsNullOrEmpty(cmbRFR.Text) ? "%" : cmbRFR.Text; string Comment = String.IsNullOrEmpty(cmbSubRFR.Text) ? "%" : cmbSubRFR.Text; string Select = "SELECT * FROM tblReject_test WHERE department_id LIKE '" + Department + "'" + "AND body_part_examined LIKE'" + Anatomy + "'" + "AND study_date LIKE'" + Start_Date + "'" + "AND study_date LIKE'" + End_Date + "'" + "AND reject_category LIKE'" + RFR + "'" + "AND reject_comment LIKE'" + Comment + "'"; //DataConnection connects to the database. string connectiontring = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=|DataDirectory|\\Database1.mdb"; DataConnection = new OleDbConnection(connectiontring); //The DataAdapter is the code that ensures both the data in the Select and DataConnection strings match. OleDbDataAdapter rdDataAdapter = new OleDbDataAdapter(Select, DataConnection); try { //It then clears the datagridview and loads the data that has been selected from the DataAdapter. database1DataSet.tblReject_test.Clear(); rdDataAdapter.Fill(this.database1DataSet.tblReject_test); } catch (OleDbException exc) { System.Windows.Forms.MessageBox.Show(exc.Message); } } //End of Search button //Temporary button thats loads the chart when clicked private void btnLoadChart_Click(object sender, EventArgs e) { charRejections.Series["RFR"].Points.Clear(); { string connectiontring = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=|DataDirectory|\\Database1.mdb"; DataConnection = new OleDbConnection(connectiontring); try { int count = database1DataSet.Tables["tblReject_test"].Rows.Count; DataConnection.Open(); OleDbCommand command = new OleDbCommand(); command.Connection = DataConnection; string query = "SELECT COUNT(*) as count, reject_category FROM tblReject_test GROUP BY reject_category"; command.CommandText = query; OleDbDataReader reader = command.ExecuteReader(); while (reader.Read()) { charRejections.Series["RFR"].Points.AddXY(reader["reject_category"].ToString(), reader[count]); } DataConnection.Close(); } catch (Exception ex) { MessageBox.Show("Error " + ex); } } } //end of load chart button //These buttons are all from the file menu bar //A simple button that closes the application private void exitToolStripMenuItem_Click(object sender, EventArgs e) { this.Close(); } //This button loads the NewRFRPopup form private void addRFRToolStripMenuItem_Click(object sender, EventArgs e) { NewRFRPopup popup = new NewRFRPopup(this); popup.ShowDialog(); } private void printChartToolStripMenuItem_Click(object sender, EventArgs e) { charRejections.Printing.PrintDocument.DefaultPageSettings.Landscape = true; charRejections.Printing.PrintPreview(); } //End of file menu bar //These buttons change the format of the chart private void btnPie_Click(object sender, EventArgs e) { this.charRejections.Series["RFR"].ChartType = System.Windows.Forms.DataVisualization.Charting.SeriesChartType.Pie; } private void btnBar_Click(object sender, EventArgs e) { this.charRejections.Series["RFR"].ChartType = System.Windows.Forms.DataVisualization.Charting.SeriesChartType.Column; } private void btnSideways_Click(object sender, EventArgs e) { this.charRejections.Series["RFR"].ChartType = System.Windows.Forms.DataVisualization.Charting.SeriesChartType.Bar; } private void btnLine_Click(object sender, EventArgs e) { this.charRejections.Series["RFR"].ChartType = System.Windows.Forms.DataVisualization.Charting.SeriesChartType.Line; } //end of chart formatting } }

Hello all just an update, I am still facing the issues of getting the chart to display the correct number of records. I have discovered where the chart is currently getting it's numbers from however it makes no sense as to why it is using those numbers. It is from a column in the database called "mpm_code" however I have never specified for the chart to use those numbers. Here are the numbers in the database:

Here is the chart

And here is my code:

using System; using System.Collections.Generic; using System.ComponentModel; using System.Data; using System.Drawing; using System.Linq; using System.Text; using System.Threading.Tasks; using System.Windows.Forms; using System.Data.OleDb; namespace RRAS { public partial class formRRAS : Form { public OleDbConnection DataConnection = new OleDbConnection(); string cmbRFR_item; public formRRAS() { InitializeComponent(); } //When the form loads it sets the intial combo box RFR item to null private void formRRAS_Load(object sender, EventArgs e) { // TODO: This line of code loads data into the 'database1DataSet.tblReject_test' table. You can move, or remove it, as needed. this.tblReject_testTableAdapter.Fill(this.database1DataSet.tblReject_test); cmbRFR.SelectedItem = ""; this.AcceptButton = btnSearch; } //AddRFR method, called in the NewRFRPopup public void AddRFR(object item) { cmbRFR.Items.Add(item); } private void change_cmbSubRFR_items() { cmbSubRFR.Items.Clear();//Clear all items in cmbSubRFR comboBox. switch (cmbRFR_item)//Adding your new items to cmbSubRFR. { case "": cmbSubRFR.Items.Add(""); cmbSubRFR.Text = ""; break; case "POSITIONING": cmbSubRFR.Items.Add(""); cmbSubRFR.Items.Add("Anatomy cut-off"); cmbSubRFR.Items.Add("Rotation"); cmbSubRFR.Items.Add("Obstructed view"); cmbSubRFR.Items.Add("Tube or grid centering"); cmbSubRFR.Items.Add("Motion"); cmbSubRFR.Text = ""; break; case "ARTEFACT": cmbSubRFR.Items.Add(""); cmbSubRFR.Items.Add("ARTEFACT"); cmbSubRFR.Text = "ARTEFACT"; cmbSubRFR.Text = ""; break; case "PATIENT ID": cmbSubRFR.Items.Add(""); cmbSubRFR.Items.Add("Incorrect Patient"); cmbSubRFR.Items.Add("Incorrect Study/Side"); cmbSubRFR.Items.Add("User Defined Error"); cmbSubRFR.Text = ""; break; case "EXPOSURE ERROR": cmbSubRFR.Items.Add(""); cmbSubRFR.Items.Add("Under Exposure"); cmbSubRFR.Items.Add("Over Exposure"); cmbSubRFR.Items.Add("Exposure Malfunction"); cmbSubRFR.Text = ""; break; case "TEST IMAGES": cmbSubRFR.Items.Add(""); cmbSubRFR.Items.Add("Quality Control"); cmbSubRFR.Items.Add("Service/Test"); cmbSubRFR.Text = ""; break; } } private void cmbRFR_SelectedIndexChanged(object sender, EventArgs e) { if (cmbRFR_item != cmbRFR.SelectedItem.ToString())//This controls the changes in cmbRFR about selected item and call change_cmbSubRFR_items() { cmbRFR_item = cmbRFR.SelectedItem.ToString(); change_cmbSubRFR_items(); } } //The code for the button that closes the application private void btnSearch_Click(object sender, EventArgs e) { //This creates the String Publisher which grabs the information from the combo box on the form. //Select and Dataconnection are also defined here. string Department = String.IsNullOrEmpty(txtDepartment.Text) ? "%" : txtDepartment.Text; string Start_Date = String.IsNullOrEmpty(txtStart.Text) ? "%" : txtStart.Text; string End_Date = String.IsNullOrEmpty(txtEnd.Text) ? "%" : txtEnd.Text; string Anatomy = String.IsNullOrEmpty(txtAnatomy.Text) ? "%" : txtAnatomy.Text; string RFR = String.IsNullOrEmpty(cmbRFR.Text) ? "%" : cmbRFR.Text; string Comment = String.IsNullOrEmpty(cmbSubRFR.Text) ? "%" : cmbSubRFR.Text; string Select = "SELECT * FROM tblReject_test WHERE department_id LIKE '" + Department + "'" + "AND body_part_examined LIKE'" + Anatomy + "'" + "AND study_date LIKE'" + Start_Date + "'" + "AND study_date LIKE'" + End_Date + "'" + "AND reject_category LIKE'" + RFR + "'" + "AND reject_comment LIKE'" + Comment + "'"; //DataConnection connects to the database. string connectiontring = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=|DataDirectory|\\Database1.mdb"; DataConnection = new OleDbConnection(connectiontring); //The DataAdapter is the code that ensures both the data in the Select and DataConnection strings match. OleDbDataAdapter rdDataAdapter = new OleDbDataAdapter(Select, DataConnection); try { //It then clears the datagridview and loads the data that has been selected from the DataAdapter. database1DataSet.tblReject_test.Clear(); rdDataAdapter.Fill(this.database1DataSet.tblReject_test); } catch (OleDbException exc) { System.Windows.Forms.MessageBox.Show(exc.Message); } } //End of Search button //Temporary button thats loads the chart when clicked private void btnLoadChart_Click(object sender, EventArgs e) { charRejections.Series["RFR"].Points.Clear(); { string connectiontring = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=|DataDirectory|\\Database1.mdb"; DataConnection = new OleDbConnection(connectiontring); try { int count = database1DataSet.Tables["tblReject_test"].Rows.Count; DataConnection.Open(); OleDbCommand command = new OleDbCommand(); command.Connection = DataConnection; string query = "SELECT COUNT(*) as count, reject_category FROM tblReject_test GROUP BY reject_category"; command.CommandText = query; OleDbDataReader reader = command.ExecuteReader(); while (reader.Read()) { charRejections.Series["RFR"].Points.AddXY(reader["reject_category"].ToString(), reader[count]); } DataConnection.Close(); } catch (Exception ex) { MessageBox.Show("Error " + ex); } } } //end of load chart button //These buttons are all from the file menu bar //A simple button that closes the application private void exitToolStripMenuItem_Click(object sender, EventArgs e) { this.Close(); } //This button loads the NewRFRPopup form private void addRFRToolStripMenuItem_Click(object sender, EventArgs e) { NewRFRPopup popup = new NewRFRPopup(this); popup.ShowDialog(); } private void printChartToolStripMenuItem_Click(object sender, EventArgs e) { charRejections.Printing.PrintDocument.DefaultPageSettings.Landscape = true; charRejections.Printing.PrintPreview(); } //End of file menu bar //These buttons change the format of the chart private void btnPie_Click(object sender, EventArgs e) { this.charRejections.Series["RFR"].ChartType = System.Windows.Forms.DataVisualization.Charting.SeriesChartType.Pie; } private void btnBar_Click(object sender, EventArgs e) { this.charRejections.Series["RFR"].ChartType = System.Windows.Forms.DataVisualization.Charting.SeriesChartType.Column; } private void btnSideways_Click(object sender, EventArgs e) { this.charRejections.Series["RFR"].ChartType = System.Windows.Forms.DataVisualization.Charting.SeriesChartType.Bar; } private void btnLine_Click(object sender, EventArgs e) { this.charRejections.Series["RFR"].ChartType = System.Windows.Forms.DataVisualization.Charting.SeriesChartType.Line; } //end of chart formatting } }

最满意答案

由于我的一位朋友,该问题已经分类。 这与TaW前几天发布的代码有关。 感谢大家的时间和建议。 固定代码如下:

private void btnLoadChart_Click(object sender, EventArgs e) { charRejections.Series["RFR"].Points.Clear(); { string connectiontring = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=|DataDirectory|\\Database1.mdb"; DataConnection = new OleDbConnection(connectiontring); try { DataConnection.Open(); OleDbCommand command = new OleDbCommand(); command.Connection = DataConnection; string query = "SELECT COUNT(reject_category) as reject, reject_category FROM tblReject_test GROUP BY reject_category"; command.CommandText = query; OleDbDataReader reader = command.ExecuteReader(); while (reader.Read()) { charRejections.Series["RFR"].Points.AddXY(reader["reject_category"].ToString(), reader["reject"].ToString()); } DataConnection.Close(); } catch (Exception ex) { MessageBox.Show("Error " + ex); } } }//end of load chart button

The Issue has been sorted thanks to a friend of mine. This relates to the code that TaW posted the other day. Thanks for everyone's time and suggestions. The fixed code is below:

private void btnLoadChart_Click(object sender, EventArgs e) { charRejections.Series["RFR"].Points.Clear(); { string connectiontring = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=|DataDirectory|\\Database1.mdb"; DataConnection = new OleDbConnection(connectiontring); try { DataConnection.Open(); OleDbCommand command = new OleDbCommand(); command.Connection = DataConnection; string query = "SELECT COUNT(reject_category) as reject, reject_category FROM tblReject_test GROUP BY reject_category"; command.CommandText = query; OleDbDataReader reader = command.ExecuteReader(); while (reader.Read()) { charRejections.Series["RFR"].Points.AddXY(reader["reject_category"].ToString(), reader["reject"].ToString()); } DataConnection.Close(); } catch (Exception ex) { MessageBox.Show("Error " + ex); } } }//end of load chart button

更多推荐

本文发布于:2023-07-30 14:58:00,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1338765.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:数量   正确   如何在   studio   display

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!