Is it possible to match two series of data in a chart from two different datasets in c# winforms

后端 未结 2 1691
忘了有多久
忘了有多久 2021-01-27 12:27

I am working on a application to chart boards inspected and board with defects based on work order number. I realize after looking at the chart and comparing the actual data, th

2条回答
  •  失恋的感觉
    2021-01-27 12:55

    I figured it out, I first changed my DataSets into DataTables. I then created a new column in DataTable 1 that will hold the count field in DataTable 2. I then looped through all the row in DataTable 1 and looped through DataTable 2 and put a select condition to match the top_or_bottom and board_wo_fields and pulled the count value for each match out of DataTable 2 and put them in DataTable 1.

    DataTable dt1 = DA.Get_Boards_Inspected(startDate, endDate, location);
                    DataTable dt2 = DA2.Get_Boards_With_Issue(startDate, endDate, location);
    
    
                    DataColumn newCol = new DataColumn("dcount", typeof(System.Object));
                    newCol.AllowDBNull = true;
                    dt1.Columns.Add(newCol);
                    foreach(DataRow r in dt1.Rows)
                    {
                        object wo = (r["board_wo_number"]).ToString();
                        object tp = (r["top_or_bottom"]).ToString();
    
                        if (tp == "")
                        {
                            foreach (DataRow r1 in dt2.Select("board_wo_number = '" + wo + "'"))
                            {
                                if (r1["count"] == DBNull.Value)
                                    r["dcount"] = 0;
                                else
                                    r["dcount"] = (r1["count"]);
                            }
                        }
                        else
                        {
                            foreach (DataRow r1 in dt2.Select("board_wo_number = '" + wo + "' and top_or_bottom = '" + tp + "'"))
                            {
                                if (r1["count"] == DBNull.Value)
                                    r["dcount"] = 0;
                                else
                                    r["dcount"] = (r1["count"]);
                            }
                        }
                    }
    
                    foreach (DataRow dr in dt1.Rows)
                    {
                        object tpn = (dr["top_or_bottom"]);
                        object ct = (dr["count"]).ToString();
                        object wo = (dr["board_wo_number"]).ToString();
                        object ct2 = (dr["dcount"]).ToString();
    
                        if (tpn == DBNull.Value)
                        {
                            chart1.Series["Boards Inspected"].Points.AddXY(wo, ct);
                            chart1.Series["Boards With Issue"].Points.AddXY(wo, ct2);
                        }
                        else
                        {
                            chart1.Series["Boards Inspected"].Points.AddXY(wo + " - " + tpn, ct);
                            chart1.Series["Boards With Issue"].Points.AddXY(wo + " - " + tpn, ct2);
                        }
                    }      
    

提交回复
热议问题