none
Plotting the graph for the acquired data RRS feed

  • Question

  • Hi,

    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 file format: 

    Date Test1 USL LSL
    01-Apr-19 7.25 8 7.25
    04-Apr-19 7.33 8 7.25
    10-10-19 7.55 8 7.25
    07-05-19 8 8 7.25

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




    Akshay



    Wednesday, April 17, 2019 10:25 AM

All replies

  • You can find many samples to display a Chart from a csv file .

    For example :  chart from csv data

    Wednesday, April 17, 2019 11:13 AM
  • Hi

    Thank you for posting here.

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

    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;
            }
    

    Result:

    Best Regards,

    Jack


    MSDN Community Support
    Please remember to click "Mark as Answer" the responses that resolved your issue, and to click "Unmark as Answer" if not. This can be beneficial to other community members reading this thread. If you have any compliments or complaints to MSDN Support, feel free to contact MSDNFSF@microsoft.com.

    Thursday, April 18, 2019 5:33 AM
    Moderator
  • Hi,

    Is it possible to plot the same type of graph as in my screenshot?


    Akshay

    Tuesday, April 23, 2019 10:51 AM
  • Hi

    Thanks for the feedback.

    The chart control does not support graphs, but it can have both histograms and bar graphs.

    If you want a histogram and a bar chart, can you tell me the relationship between the Y-axis corresponding to the X-axis?

    Best Regards,

    Jack


    MSDN Community Support
    Please remember to click "Mark as Answer" the responses that resolved your issue, and to click "Unmark as Answer" if not. This can be beneficial to other community members reading this thread. If you have any compliments or complaints to MSDN Support, feel free to contact MSDNFSF@microsoft.com.

    Thursday, April 25, 2019 6:05 AM
    Moderator