[DevExpress] Statistically display a column of data as a histogram

Display results preview:

As shown above: The R15101 device is counted according to FAULT/WARNING results in FAULT_LEVEL and displayed in the form of a histogram.

Operation steps:

(1) Find out the data list from the database according to the specified conditions and count the number of FAULT/WARNING bars with Linq statement, then transmit it to the client.

 int level_fault_count = fdcfaulttrxlist.Where(t=>t.FaultLevel=="FAULT").Count();
 int level_warning_count = fdcfaulttrxlist.Where(t=>t.FaultLevel=="WARNING").Count();

(2) After the client obtains the data, bind the list to the GridView, and then use the data in the DataTable to draw the ChartControl.

 private void btnSearch_ItemClick(object sender, DevExpress.XtraBars.ItemClickEventArgs e)
        {
            DataTable dt = new DataTable();
            if (dtFrom.EditValue != null && dtTo != null&&gluResId.EditValue!=null&&dtFrom.EditValue.ToString()!=""&&dtTo.EditValue.ToString()!=""
                &&gluResId.EditValue.ToString()!="")
            {
                string sStartTime = CommonFunction.ToStandardTime((DateTime)dtFrom.EditValue, GlobalConstant.SYS_CONVERT_DATETIME_FORMAT);
                string sEndTime = CommonFunction.ToStandardTime((DateTime)dtTo.EditValue, GlobalConstant.SYS_CONVERT_DATETIME_FORMAT);
                string sResId = gluResId.EditValue.ToString();
                chtSummary.Series.Clear();
                BindGV();
            }
        }

BindGV():

  private bool BindGV()
        {
            if (dtFrom.EditValue == null || dtTo.EditValue == null)
            {
                return false;
            }
            if (gluResId.EditValue == null || gluResId.EditValue.ToString() == "")
            {
                DataTable dtResult = new DataTable();
                
                dtResult.Columns.Add("PARA_DISPLAY_NAME");
                dtResult.Columns.Add("FAULT_TIME");
                dtResult.Columns.Add("DATA_CATEGORY");
                dtResult.Columns.Add("SPEC_TYPE");
                dtResult.Columns.Add("FAULT_TYPE");
                dtResult.Columns.Add("FAULT_LEVEL");
                dtResult.Columns.Add("DATA_STATUS");
                dtResult.Columns.Add("PARA_VALUE");
                dtResult.Columns.Add("TARGET");
                dtResult.Columns.Add("USL");
                dtResult.Columns.Add("UCL");
                dtResult.Columns.Add("LCL");
                dtResult.Columns.Add("LSL");
                dtResult.Columns.Add("FAULT_DESC");
                dtResult.Columns.Add("OPERATION_ID");
                dtResult.Columns.Add("LOT_ID");
                dtResult.Columns.Add("LOT_TYPE");
                dtResult.Columns.Add("CASSETTE_SLOT");
                dtResult.Columns.Add("SUBSTRATE_ID");
                dtResult.Columns.Add("PRODUCT_ID");
                dtResult.Columns.Add("RECIPE_ID");
                dtResult.Columns.Add("STEP_ID");
                dtResult.Columns.Add("MAIN_MODULE_ID");
                dtResult.Columns.Add("CONTEXT_KEY");
                dtResult.Columns.Add("INTERLOCK_FLAG");
                dtResult.Columns.Add("COMPOSITE");
                dtResult.Columns.Add("CMF_01");
                dtResult.Columns.Add("CMF_02");
                dtResult.Columns.Add("CMF_03");
                dtResult.Columns.Add("CMF_04");
                dtResult.Columns.Add("CMF_05");
                dtResult.Columns.Add("CMF_06");
                dtResult.Columns.Add("CMF_07");
                dtResult.Columns.Add("CMF_08");
                dtResult.Columns.Add("CMF_09");
                dtResult.Columns.Add("CMF_10");
                dtResult.Columns.Add("CMF_11");
                dtResult.Columns.Add("CMF_12");
                dtResult.Columns.Add("CMF_13");
                dtResult.Columns.Add("CMF_14");
                dtResult.Columns.Add("CMF_15");
                dtResult.Columns.Add("CMF_16");
                dtResult.Columns.Add("CMF_17");
                dtResult.Columns.Add("CMF_18");
                dtResult.Columns.Add("CMF_19");
                dtResult.Columns.Add("CMF_20");
                dtResult.Columns.Add("CREATE_USER_ID");
                dtResult.Columns.Add("CREATE_TIME");
                dtResult.Columns.Add("UPDATE_USER_ID");
                dtResult.Columns.Add("UPDATE_TIME");
                dtResult.Columns.Add("LEVEL_FAULT_COUNT");
                dtResult.Columns.Add("LEVEL_WARNING_COUNT");
                dtResult.Columns.Add("RAWID");
                dtResult.Columns.Add("RES_ID");
                dtResult.Columns.Add("DCP_ID");
                int[] iaWidth = new int[dtResult.Columns.Count];
                for (int i = 0; i < dtResult.Columns.Count; i++)
                {
                    if (i < 50)
                        iaWidth[i] = 80;
                    else
                        iaWidth[i] = -1;
                }
                DevGridControlHelper.BindData(gdcSummary, dtResult, iaWidth);

               
                return false;
            }
            string sResId = gluResId.EditValue.ToString();
            DateTime tFrom = DateCheck.Checked ? ((DateTime)dtFrom.EditValue) : DateTime.Now.AddDays(-1);//ToDo: Query all work orders with a previous date simulation
            DateTime tTo = DateCheck.Checked ? ((DateTime)dtTo.EditValue) : DateTime.Now;//Make sure you find the PO you created today. Adding seconds instead of adding one day is to avoid AddDays (after) second days of data ToDo: second should be AddDays(1).
            DataTable dt = ListRoutineFDC.ViewFDCAlarmSummary(sResId: sResId, sStartTime: CommonFunction.ToStandardTime(tFrom, GlobalConstant.SYS_CONVERT_DATETIME_FORMAT),
                sEndTime: CommonFunction.ToStandardTime(tTo, GlobalConstant.SYS_CONVERT_DATETIME_FORMAT));
            if (dt != null)
            {
                int[] iaWidth = new int[dt.Columns.Count];
                for (int i = 0; i < dt.Columns.Count; i++)
                {
                    if (i < 50)
                        iaWidth[i] = 80;
                    else
                        iaWidth[i] = -1;//A total of 55 columns, the last five columns are not displayed
                }
                DevGridControlHelper.BindData(gdcSummary, dt, iaWidth);
                ChartControl stackedBarChart = new ChartControl();
                Series[] aSeries = CreateSeries(dt, ViewType.SideBySideStackedBar);//The data to be displayed is bound to series
                //((LineSeriesView)series.View).MarkerVisibility = DevExpress.Utils.DefaultBoolean.True;
                //((LineSeriesView)series.View).LineMarkerOptions.Size = 5;
                //chtSummary.Series.AddRange(aSeries);
                ((SideBySideStackedBarSeriesView)aSeries[0].View).StackedGroup = 0;//// Grouping two series on the same stack.
                ((SideBySideStackedBarSeriesView)aSeries[1].View).StackedGroup = 0;
                stackedBarChart.Dock = DockStyle.Fill;

                chtSummary.Series.AddRange(aSeries);
                // gdvDetail.Columns[0].Width = 20;
                return true;
            }
            else
            {
                DataTable dtResult = new DataTable();
                
                dtResult.Columns.Add("PARA_DISPLAY_NAME");
                dtResult.Columns.Add("FAULT_TIME");
                dtResult.Columns.Add("DATA_CATEGORY");
                dtResult.Columns.Add("SPEC_TYPE");
                dtResult.Columns.Add("FAULT_TYPE");
                dtResult.Columns.Add("FAULT_LEVEL");
                dtResult.Columns.Add("DATA_STATUS");
                dtResult.Columns.Add("PARA_VALUE");
                dtResult.Columns.Add("TARGET");
                dtResult.Columns.Add("USL");
                dtResult.Columns.Add("UCL");
                dtResult.Columns.Add("LCL");
                dtResult.Columns.Add("LSL");
                dtResult.Columns.Add("FAULT_DESC");
                dtResult.Columns.Add("OPERATION_ID");
                dtResult.Columns.Add("LOT_ID");
                dtResult.Columns.Add("LOT_TYPE");
                dtResult.Columns.Add("CASSETTE_SLOT");
                dtResult.Columns.Add("SUBSTRATE_ID");
                dtResult.Columns.Add("PRODUCT_ID");
                dtResult.Columns.Add("RECIPE_ID");
                dtResult.Columns.Add("STEP_ID");
                dtResult.Columns.Add("MAIN_MODULE_ID");
                dtResult.Columns.Add("CONTEXT_KEY");
                dtResult.Columns.Add("INTERLOCK_FLAG");
                dtResult.Columns.Add("COMPOSITE");
                dtResult.Columns.Add("CMF_01");
                dtResult.Columns.Add("CMF_02");
                dtResult.Columns.Add("CMF_03");
                dtResult.Columns.Add("CMF_04");
                dtResult.Columns.Add("CMF_05");
                dtResult.Columns.Add("CMF_06");
                dtResult.Columns.Add("CMF_07");
                dtResult.Columns.Add("CMF_08");
                dtResult.Columns.Add("CMF_09");
                dtResult.Columns.Add("CMF_10");
                dtResult.Columns.Add("CMF_11");
                dtResult.Columns.Add("CMF_12");
                dtResult.Columns.Add("CMF_13");
                dtResult.Columns.Add("CMF_14");
                dtResult.Columns.Add("CMF_15");
                dtResult.Columns.Add("CMF_16");
                dtResult.Columns.Add("CMF_17");
                dtResult.Columns.Add("CMF_18");
                dtResult.Columns.Add("CMF_19");
                dtResult.Columns.Add("CMF_20");
                dtResult.Columns.Add("CREATE_USER_ID");
                dtResult.Columns.Add("CREATE_TIME");
                dtResult.Columns.Add("UPDATE_USER_ID");
                dtResult.Columns.Add("UPDATE_TIME");
                dtResult.Columns.Add("LEVEL_FAULT_COUNT");
                dtResult.Columns.Add("LEVEL_WARNING_COUNT");
                dtResult.Columns.Add("RAWID");
                dtResult.Columns.Add("RES_ID");
                dtResult.Columns.Add("DCP_ID");

                int[] iaWidth = new int[dtResult.Columns.Count];
                for (int i = 0; i < dtResult.Columns.Count; i++)
                {
                    if (i < 50)
                        iaWidth[i] = 80;
                    else
                        iaWidth[i] = -1;
                }
                DevGridControlHelper.BindData(gdcSummary, dtResult, iaWidth);

                return false;
            }
        }

       

The data to be displayed is bound to series, CreateSeries ():

   private Series[] CreateSeries(DataTable dt, ViewType viewType)
        {
            Series[] aSeries = new Series[2];
            Series series1 = new Series("FAULT", viewType);//Two different data results
            Series series2 = new Series("WARNING", viewType);
            int count = dt.Rows.Count;
            try
            {
                int dNum_Fault = Convert.ToInt32(dt.Rows[0]["LEVEL_FAULT_COUNT"]);//Statistical Result Value
              
                int dNum_Warning = Convert.ToInt32(dt.Rows[0]["LEVEL_WARNING_COUNT"]);
                string sResId = dt.Rows[0]["RES_ID"].ToString();//The name of the R15101 histogram
                series1.Points.Add(new SeriesPoint(sResId, dNum_Fault));
                series2.Points.Add(new SeriesPoint(sResId, dNum_Warning));
                aSeries.SetValue(series1,0);
                aSeries.SetValue(series2,1);
            }
            catch (Exception ex)
            {
                CommonFunction.ShowMsgBox(ex.Message);
                series1.Points.Clear();
                series2.Points.Clear();
                return aSeries;
            }
            
            //series.ArgumentScaleType = ScaleType.DateTime;
            // series.LabelsVisibility = DevExpress.Utils.DefaultBoolean.True;//Display tag

            return aSeries;
        }

Demonstration of DevExpress official website columnar diagram

 

Note: Data can be found in the background, but the data of other columns can not be obtained by the front desk. Check it patiently. It may be that a field in the list is missing and the field name is wrong when binding.

Keywords: Programming Database

Added by kopytko on Wed, 02 Oct 2019 17:14:49 +0300