绘制采集数据的图形 [英] Plotting the graph for the acquired data

查看:91
本文介绍了绘制采集数据的图形的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想生成从CSV文件中取出LSL和USL的图形,中心将是平均值。 (我只需要
曲线内不是整体

I want to generate the graph which fetches LSL and USL from the CSV file and the center will be the mean. ( I need only within curve not overall

CSV文件格式: 

CSV file format: 

我有从CSV数据生成的Cp,Cpk值

I have Cp,Cpk values generated from the data of CSV







Akshay

推荐答案

您好

感谢您在此发帖。

根据您的描述,您希望生成从CSV文件中获取LSL和USL的图形。

Based on your description, you want to generate the graph which fetches LSL and USL from the CSV file.

您可以尝试e代码如下。

You could try the following code.

private void Button1_Click(object sender, EventArgs e)
        {
            button1.Enabled = false;
            OpenFileDialog openFileDialog1 = new OpenFileDialog();
            openFileDialog1.Filter = ("comma seperated value | *.CSV");
            if (openFileDialog1.ShowDialog() == DialogResult.OK)
            {
                string strfilename = openFileDialog1.FileName;
                if (File.Exists(strfilename))
                {
                    textBox1.Text = strfilename;
                }
                else
                {

                    strfilename = "";
                }
                if (!string.IsNullOrWhiteSpace(strfilename))
                {
                    textBox1.Text = strfilename;
                }
                else
                {
                    MessageBox.Show("Please select a file");
                }
            }
            else
            {
                MessageBox.Show("Please select a file");
            }
        }
        private static DataTable GetDataTabletFromCSVFile(string csv_file_path)
        {
            DataTable csvData = new DataTable();
            try
            {
                using (TextFieldParser csvReader = new TextFieldParser(csv_file_path))
                {
                    csvReader.SetDelimiters(new string[] { "," });
                    csvReader.HasFieldsEnclosedInQuotes = true;
                    string[] colFields = csvReader.ReadFields();
                    foreach (string column in colFields)
                    {
                        if (column == "Date" || column == "Test1" || column == "USL" || column == "LSL")
                        {
                           DataColumn datecolumn = new DataColumn(column);
                            datecolumn.AllowDBNull = true;
                            csvData.Columns.Add(datecolumn);
                        }
                    }
                    while (!csvReader.EndOfData)
                    {
                        string[] fieldData = csvReader.ReadFields();
                        for (int i = 0; i < fieldData.Length; i++)
                        {
                            if (fieldData[i] == "")
                            {
                                fieldData[i] = null;
                            }
                        }
                        csvData.Rows.Add(fieldData);
                    }
                }

            }
            catch (Exception)
            {
                throw;
            }
            return csvData;
        }

        private void Button2_Click(object sender, EventArgs e)
        {
            DataTable table = GetDataTabletFromCSVFile(textBox1.Text);
            this.chart1.Series.Clear();

            this.chart1.Titles.Add("Total Income");
            chart1.DataSource = table;
            Series series = this.chart1.Series.Add("Total Income");
            series.XValueMember = "Date";
            series.YValueMembers = "LSL";
            this.chart1.Series[0].ChartType= SeriesChartType.Line;
            this.chart1.Series[0].Color = Color.Blue;
        }

结果:

最好的问候,

杰克


这篇关于绘制采集数据的图形的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆